Reputation: 193
how can I add to each node I add to xml a unique index value for example I have
<events>
<event><id>0</id>
</event>
<event><id>1</id></event>
</events>
I want to add another event "node" that the id will be 6
/edited/
i have created xsd an added to the id elment autoincrease =true but idont really know what to do next ? help
Upvotes: 0
Views: 1038
Reputation: 25692
The easiest way to serialize an attribute with an object is to decorate the property with [XmlAttribute]
. Here is a simple example of a class representing your <event>
element:
[XmlType(TypeName="event")]
public class Event
{
[XmlAttribute("id")]
public int ID { get; set; }
}
You might get some mileage out of the Xsd.exe command line tool. In some cases, the tool can save you a lot of hand-decorating classes for serialization. It can be used in a two-step fashion to:
Upvotes: 1