我想在程序中把
张强
2
true
时间
定时存到xml文件中,然后后在读取
怎么写代码,又没有例子。

解决方案 »

  1.   

    比如格式是:
    <stu>
      <row id="1">
        <name>A</name>
        <age>22</age>
      </row>
    </stu>操作如下:
    public void InsertNode()
            {
                int IntRowCount = 0;
                XmlDocument xml_Doc = new XmlDocument();
                xml_Doc.Load(@"C:\stu.xml");
                int IntMax = 0;
                XmlNodeList node_list = xml_Doc.ChildNodes;
                XmlNode node = null;
                if (node_list != null && node_list.Count > 0)
                {
                    node = node_list[0];
                    XmlNodeList list = node.ChildNodes;
                    IntRowCount = list.Count;
                    node = list.Item(IntRowCount - 1);
                    IntMax = int.Parse(node.Attributes["id"].Value);
                }
                IntMax++;
                XmlNode append_Node = node_list[0].ChildNodes[0].Clone();
                append_Node.Attributes["id"].Value = IntMax.ToString();
                IntRowCount = append_Node.ChildNodes.Count;
                append_Node.ChildNodes[0].InnerText = "BB";
                append_Node.ChildNodes[1].InnerText = "25";
                xml_Doc.ChildNodes[0].AppendChild(append_Node);
                xml_Doc.Save(@"d:\BB.xml");
            }执行后如下
    <stu>
      <row id="1">
        <name>A</name>
        <age>22</age>
      </row>
    <row id="2">
        <name>BB</name>
        <age>25</age>
      </row>
    </stu>
      

  2.   

    你得先大致定义一个Xml的大体结构吧..