how can I add to each node I add to xml a unique index value for example I have
<events&开发者_JS百科gt;
<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
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:
- Generate a XSD validation schema for a sample XML file.
- Generate serializable .NET classes based on the XSD schema.
精彩评论