<?xml version="1.0" encoding="utf-8" ?> 
<book>
<lovel>
<name>jim</name>
<author>罗曼罗兰</author>
</lovel>
<lovel>
<name>lucy</name>
<author>杰克逊</author>
</lovel>
</book>我可以根据"jim"找到"罗曼罗兰"这个信息吗?
要是有的话,怎么的一个读法,还有就是怎么添加节点!!!我刚刚接触XML,急着用,没办法,请各位帮忙!!!!!

解决方案 »

  1.   

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <MotherTongue lalTitle = "24小时天气预报"
      lalWeatherType = "天气类型"
      lalMax = "最高温度"
      lalMin = "最低温度"
      btnSet="设置"
      title="天气预报" 
      btnCancel="取消"
         >
    </MotherTongue>
    <English lalTitle = "24-hour weather forecast"
      lalWeatherType = "weather type"
      lalMax = "maximum temperature"
      lalMin = "minimum temperature"
      btnSet="set"
      title="weather forecast" 
      btnCancel="cancel"
                 >
    </English>
    </configuration>
      void LoadCfgFile()
            {            XmlDocument x = new XmlDocument();
                x.Load("LanguageXml/WeatherForm.xml");
                switch (MainForm._nLanguage)
                {
                    case 1:
                        XmlNodeList xnl = x.SelectNodes("/configuration/MotherTongue");
                        this.lalMax.Text = xnl[0].Attributes["lalMax"].InnerText;
                        this.lalMin.Text = xnl[0].Attributes["lalMin"].InnerText;
                        this.lalTitle.Text = xnl[0].Attributes["lalTitle"].InnerText;
                        this.btnSet.Text = xnl[0].Attributes["btnSet"].InnerText;
                        this.btnCancel.Text = xnl[0].Attributes["btnCancel"].InnerText;
                        this.lalWeatherType.Text = xnl[0].Attributes["lalWeatherType"].InnerText;
                        this.Text = xnl[0].Attributes["title"].InnerText;
                        break;
                    case 2:
                        XmlNodeList xnl1 = x.SelectNodes("/configuration/English");
                        this.lalMax.Text = xnl1[0].Attributes["lalMax"].InnerText;
                        this.lalMin.Text = xnl1[0].Attributes["lalMin"].InnerText;
                        this.lalTitle.Text = xnl1[0].Attributes["lalTitle"].InnerText;
                        this.btnSet.Text = xnl1[0].Attributes["btnSet"].InnerText;
                        this.btnCancel.Text = xnl1[0].Attributes["btnCancel"].InnerText;
                        this.lalWeatherType.Text = xnl1[0].Attributes["lalWeatherType"].InnerText;
                        this.Text = xnl1[0].Attributes["title"].InnerText;
                        break;            }
            }
      

  2.   

    用我这个,包你搞定,接分~~static string Search()
            {
                string author="";
                XmlDocument doc = new XmlDocument();
                doc.Load(@"你XML文件的路径");
                XmlNodeList nodelist = doc.SelectSingleNode("book").ChildNodes;
                foreach (XmlNode xn in nodelist)
                {               
                    string name = node.SelectSingleNode("name").InnerText;
                    if(name.equal("jim"))
                    {
                        author= node.SelectSingleNode("author").InnerText;
                    }
                }
                return author;
           }
      

  3.   

    XmlNode node = doc.SelectSingleNode("/book/lovel[name='jim']/author");
    node.InnerText就是
      

  4.   


    二楼的大虾请回答:
    说node没有定义,应该是什么类型的?还有就是你的一点错误,String中不含equal()而是Equals()
      

  5.   

    static string Search()
            {
                
                string author = "";
                XmlDocument doc = new XmlDocument();
                doc.Load("I:\\book.xml");
                XmlNodeList nodelist = doc.SelectSingleNode("book").ChildNodes;
                XmlNode node = doc.SelectSingleNode("/book/lovel[name='jim']/author"); 
                foreach (XmlNode xn in nodelist)
                {
                    string name = node.SelectSingleNode("name").InnerText;
                    if (Object.Equals(name, "jim"))
                    {
                        author = node.SelectSingleNode("author").InnerText;
                    }
                }
                return author;
            }string name = node.SelectSingleNode("name").InnerText;
    这句话老出错!!
    说什么"new"关键字创建对象实例;调用前检查确定对象是否为空!!我把它先定义String name = "name";
    还是不行!!怎么回事???
      

  6.   

    static string Search()
            {
                string author="";
                XmlDocument doc = new XmlDocument();
                doc.Load("你XML文件的路径");
                XmlNodeList nodelist = doc.SelectSingleNode("book").ChildNodes;
                foreach (XmlNode xn in nodelist)
                {               
                    string name = xn.SelectSingleNode("name").InnerText;
                    if(name.equal("jim"))
                    {
                        author= xn.SelectSingleNode("author").InnerText;
                    }
                }
                return author;
           }
      

  7.   

    12楼正解,不过还是要改一个地方:
    name.equal("jim") 改为 name.Equals("jim")谢谢各位的热心帮忙结贴,散分喽!!!!
    哈哈哈