日期:2014-05-17  浏览次数:20716 次

关于C# XML解析
现有XML文档如:<item id="totid">0</item>,请教大神,如果用C#语句通过匹配“totid”来获取“0”这个值,代码该如何写~~~
c# xml

------解决方案--------------------
也可以用linq to xml

<?xml version="1.0" encoding="utf-8" ?>
<test>
  <item id="totid">0</item>
  <item id="totid1">1</item>
  <item id="totid2">2</item>
  <item id="totid3">3</item>
  <item id="totid4">4</item>
</test>



            string path = @"H:\DavidTest\DavidMeeting\test.xml";
            XElement root = XElement.Load(path);
            var searchObj = from ele in root.Elements("item").Attributes("id")
                            where ele.Value == "totid"
                            select ele.Parent;