Given :-
[XmlRoot("Book")]
public class Book
{
[XmlAttribute]
public string Title;
[XmlElement]
public string Publisher;
[XmlElement]
public string PublisherReference;
}
When serialized to XML will give
<Book Title="My Book">
<Publisher>Some Publisher</Publisher>
<PublisherReference>XYZ123</PublisherReference>
</Book>
How could I get PublisherReference as an attribute of Publisher - e.g.
<Book Title="My Book">
<Publisher Reference="XYZ123">Some Publisher</Publisher>
</Book>
[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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With