Deserialization of an XML to C# class
XML
<Book Title="My Book">
<Publisher Reference="XYZ123">Some Publisher</Publisher>
</Book>
Class
|
[XmlRoot("Book")]
public class Book
{
[XmlAttribute]
public string Title;
[XmlElement]
public Publisher Publisher;
}
[Serializable]
public class Publisher
{
[XmlText]
public string Value;
[XmlAttribute]
public string Reference;
}
Book res = new
Book ();
XmlTextReader reader = new XmlTextReader("file path");
res = (Book)serializer.Deserialize(reader);
Ref
stackoverflow
|