<?xml version="1.0" encoding="utf-8"?>
<users>
<radiostation name="radiostation1">
<country>1</country>
<genre>2</genre>
<subgenre />
<title>3</title>
<urlwww>https://</urlwww>
<ico />
</radiostation>
<users>
[Serializable]
[XmlRoot(ElementName = "users", Namespace = "")]
public class Test
{
[XmlElement("name")]
public string Name { get; set; }
[XmlElement("country")]
public string Country { get; set; }
[XmlElement("genre")]
public string Genre { get; set; }
[XmlElement("subgenre")]
public string Subgenre { get; set; }
[XmlElement("title")]
public string Title { get; set; }
[XmlElement("urlwww")]
public string Urlwww { get; set; }
[XmlElement("ico")]
public string Ico { get; set; }
}
private T LoadFile<T>(string filePath)
{
using (var fileStream = new FileStream(XMLFileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
var serializer = new XmlSerializer(typeof(T));
return (T)serializer.Deserialize(fileStream);
}
}
var xmlTests = LoadFile<Test>(XMLFileName);
if (xmlTests.Title == MainForm.nameStation)
{
editTitleRadiostation.Text = xmlTests.Name;
editCountryPanel.Text = xmlTests.Country;
editGenrePanel.Text = xmlTests.Genre;
editSubGenrePanel.Text = xmlTests.Subgenre;
editUrlPanel.Text = xmlTests.Urlwww;
editIcoPanel.Text = xmlTests.Ico;
}
[XmlRoot(ElementName = "radiostation")]
public class Radiostation
{
[XmlElement(ElementName = "country")]
public string Country { get; set; }
[XmlElement(ElementName = "genre")]
public string Genre { get; set; }
[XmlElement(ElementName = "subgenre")]
public string Subgenre { get; set; }
[XmlElement(ElementName = "title")]
public string Title { get; set; }
[XmlElement(ElementName = "urlwww")]
public string Urlwww { get; set; }
[XmlElement(ElementName = "ico")]
public string Ico { get; set; }
[XmlAttribute(AttributeName = "name")]
public string Name { get; set; }
}
[XmlRoot(ElementName = "users")]
public class Users
{
[XmlElement(ElementName = "radiostation")]
public Radiostation Radiostation { get; set; }
}
[Serializable]
[XmlRoot(ElementName = "radiostation")]
public class Radiostation
{
[XmlElement(ElementName = "country")]
public string Country { get; set; }
[XmlElement(ElementName = "genre")]
public string Genre { get; set; }
[XmlElement(ElementName = "subgenre")]
public string Subgenre { get; set; }
[XmlElement(ElementName = "title")]
public string Title { get; set; }
[XmlElement(ElementName = "urlwww")]
public string Urlwww { get; set; }
[XmlElement(ElementName = "ico")]
public string Ico { get; set; }
[XmlAttribute(AttributeName = "name")]
public string Name { get; set; }
}
[Serializable]
[XmlRoot(ElementName = "users")]
public class Members
{
[XmlElement(ElementName = "radiostation")]
public Radiostation Radiostation { get; set; }
}
var fileStream = new FileStream(XMLFileName, FileMode.Open);
XmlSerializer serializer = new XmlSerializer(typeof(Radiostation));
var _nds = (Radiostation)serializer.Deserialize(fileStream);
editTitleRadiostation.Text = _nds.Name;
editCountryPanel.Text = _nds.Country;
editGenrePanel.Text = _nds.Genre;
editSubGenrePanel.Text = _nds.Subgenre;
editUrlPanel.Text = _nds.Urlwww;
editIcoPanel.Text = _nds.Ico;