假如    窗体上 有个  让输入姓名的文本框,   
  输入后点添加  往一个XML文件里写<Info>
<Name>文本框的Text值</Name>
</Info>而且还得在指定的节点内 
 就是说我找所有的节点   如果节点是<Info>了  就往里面插入<Name>文本框的Text值</Name>
   这个该怎么弄啊?麻烦给提个醒    谢谢大家了

解决方案 »

  1.   

    下面的文章应该有你需要的,查找已经插入.
    C#操作xml文件入门
    http://www.knowsky.com/340889.html
      

  2.   

    这是简单的xml操作,可以参考下面代码,
    using System;
    using System.IO;
    using System.Text;
    using System.Diagnostics;
    using System.Threading;
    using System.Collections;
    using System.Data;
    using System.Xml;
    using System.Management;
    using System.Net;
    namespace Zhzuo
    {
    class ZZConsole
    {
    [STAThread]
    static void Main(string[] args)
    {
    string strXml="<?xml version=\"1.0\"?>"
    +"<Data>"
    +"<Head>"
    +"<Nodeid>1111</Nodeid>"
    +"<Subid>2222</Subid>"
    +"<Version>2004</Version>"
    +"<Date>20040302</Date>"
    +"<Time>101500</Time>"
    +"</Head>"
    +"<Body>"
    +"<Code>01</Code>"
    +"<Name>深圳</Name>"
    +"<IdType>0</IdType>"
    +"<Idno>110258740824082</Idno>"
    +"</Body>"
    +"</Data>";
    XmlDocument doc = new XmlDocument();
    doc.LoadXml(strXml);
    string vv;

    XmlNodeList myNodes = doc.GetElementsByTagName("Version");
    vv = myNodes[0].InnerText;
    //修改
    myNodes[0].InnerText = "123455";
    Console.WriteLine(vv);
    myNodes = doc.SelectNodes("//Version");
    vv = myNodes[0].InnerText;
    Console.WriteLine(vv);
    //修改
    myNodes[0].InnerText = "67890";
    doc.Save("d:\\text.xml");
    Console.ReadLine();
    }

    }

    }需要添加节点只需要调用
    using System;
    using System.IO;
    using System.Xml;public class Sample {  public static void Main() {    XmlDocument doc = new XmlDocument();
        doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
                    "<title>Pride And Prejudice</title>" +
                    "</book>");    XmlNode root = doc.DocumentElement;    //Create a new node.
        XmlElement elem = doc.CreateElement("price");
        elem.InnerText="19.95";    //Add the node to the document.
        root.AppendChild(elem);    Console.WriteLine("Display the modified XML...");
        doc.Save(Console.Out);  }
    }