开发者

unique id to record xml

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:

  1. Generate a XSD validation schema for a sample XML file.
  2. Generate serializable .NET classes based on the XSD schema.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜