<?xml version="1.0" ?> 
- <xml>
  <s sortName="三井" id="4717" sortId="103">三井</s> 
  <s sortName="其他" id="4721" sortId="103">其它</s> 
  </xml>XElement.Load("xml.xml").Elements("xml");
foreach (XElement element in enumerable)
 {
   string sortName = string.Format("{0}", element.Element("sortName").Value);
   string sortId = string.Format("{0}", element.Element("sortId").Value);
   MessageBox.Show(sortName);//这里为空读不到
 }

解决方案 »

  1.   

    你读取错误。
    这段代码,你里面没有节点 sortName 吧。
      

  2.   

    先读取一行数据,再解析,或者把其转换为类似config的文件,看你喜欢那种
      

  3.   

    参考http://blog.csdn.net/chinajiyong/article/details/7485019
      

  4.   

    LZ还是要看一下LINQ TO XML的基本操作。
      

  5.   

     XmlDocument doc = new XmlDocument();
                //装载XML文档 
                doc.Load("../../../StatService/Config.xml");            //遍历所有节点 
                foreach (XmlNode node in doc.DocumentElement.ChildNodes)
                {
                    //属性值
                    string sortName = node.Attributes["sortName"].Value;
                    //文本值
                    string s = node.InnerText; 
               }
      

  6.   


    运行提示:未将对象引用设置到对象的实例。string sortName = node.Attributes["sortName"].Value;