<?xml version="1.0" encoding="utf-8"?>
<Root>
  <user>
    <id>1</id>
    <content>no</content>
    <ip>127.0.0.1</ip>
    <time>2008-9-2 16:07:35</time>
  </user>
  <user>
    <id>2</id>
    <content>ok</content>
    <ip>127.0.0.1</ip>
    <time>2008-9-2 16:08:43</time>
  </user>
</Root>如上面的一个示例XML文件,继续往根元素Root里添加user节点时,user节点的id自动增长,如何做?

解决方案 »

  1.   

    那你为什么不用DataTable,做完数据以后用DataTable.WriteXml
      

  2.   

    用.NET的DataSet,里面有个自动增长列
    <xs:element name="Id" msdata:ReadOnly="true" msdata:AutoIncrement="true" msdata:AutoIncrementSeed="1" msdata:AutoIncrementStep="2" msprop:Generator_UserColumnName="Id" msprop:Generator_ColumnPropNameInRow="Id" msprop:Generator_ColumnVarNameInTable="columnId" msprop:Generator_ColumnPropNameInTable="IdColumn" type="xs:int" />
      

  3.   

    我要实现的是用XML做数据库实现留言的功能.第一次留言生成一个以文章ID命名的xml文件.
    如:20.xml
    <?xml version="1.0" encoding="utf-8"?>
    <Root>
      <user>
        <id>1</id>
        <content>你好啊!</content>
        <time>2008-9-2 16:07:35</time>
      </user>
    </Root>那么第二次留言如何实现往ID上加1?
    XmlDocument XMLDoc = new XmlDocument();
    XMLDoc.Load(Server.MapPath("20.XML"));
    XmlNode XMLdoCSelect = XMLDoc.SelectSingleNode("Root");
    XmlElement el = XMLDoc.CreateElement("user");
    XmlElement id = XMLDoc.CreateElement("id");
    id.InnerText = 这里怎么实现往上一记录加1;
    el.AppendChild(id);
    请给出代码.