I have a simple class in C# that I have setup to serialize to XML by using the XmlSerializer class.
[Serializable, XmlRoot("dc", Namespace= dc.NS_DC)]
public class DCItem {
// books??
[XmlElement("title")]
public string Title { get; set; }
}
DCItem serializes great as the code is setup right now (as seen above); however, I would like to change the property “Title” so that it is contained within a “Books” node. For example:
<dc>
<books>
<title>Joe's Place</title>
</books>
</dc>
What’s the best way to go about doing this?
You could define a Books class:
and then:
Also notice that I have gotten rid of the Serializable attribute which is used by binary serializers and completely ignored by the XmlSerializer class.
Now since I suspect that you could have multiple books:
you could adapt your object model to match this structure: