XmlDocument doc = new XmlDocument();
            doc.LoadXml(
                "<configuration>" + "<appSettings> " +
                        "<add key='title' value ='整合平台-解析工具'/>" +
                        "</appSettings>" + "</configuration>");            XmlNodeList node = doc.SelectNodes("//configuration/appSettings");
            XmlNode elem = node[0];             Note that InnerText does not include the up.
            Console.WriteLine("Display the InnerText of the element...");
            Console.WriteLine(elem.Attributes["key"].InnerText);             InnerXml includes the up of the element.
            Console.WriteLine("Display the InnerXml of the element...");
            Console.WriteLine(elem.InnerXml);             Set InnerText to a string that includes up.  
             The up is escaped.
            elem.InnerText = "Text containing <up/> will have char(<) and char(>) escaped.";
            Console.WriteLine(elem.OuterXml);             Set InnerXml to a string that includes up.  
             The up is not escaped.
            elem.InnerXml = "Text containing <up/>.";
            Console.WriteLine(elem.OuterXml);报错了,为什么?为什么获取不到属性值?

解决方案 »

  1.   

    doc.SelectNodes("/configuration/appSettings")
      

  2.   

    我改为doc.SelectNodes("/configuration/appSettings")后还是不行
      

  3.   

    XmlDocument xmldocument=new XmlDocument();
        xmldocument.Load("");
        foreach(XmlNode node in xmldocument.SelectSingleNode("appSettings").ChildNodes)
        {  
         if (node.Name == "add")
         {  
          if (node.Attributes.GetNamedItem("key").Value == "")
          {
          
          }  
         }  
        }
      
      

  4.   

    为什么doc.SelectNodes("/configuration/appSettings")这样写不行?