您的位置:首页 > 其它

如何在XElement中使用XPath

2012-05-14 16:29 169 查看
在XElement中并没有对XPath的支持,需要通过扩展实现,扩展类为System.Xml.XPath.Extensions。所以通过引用System.Xml.XPath命名空间后即可使用XPath方式筛选元素。例子如下:

string xml = "<body><scoreLogSchema><item><logTime>20100326170319</logTime><score>100</score></item><item><logTime>20100325150315</logTime><score>999</score></item></scoreLogSchema></body>";

var elem = XElement.Parse(xml);

Response.Write(elem.XPathSelectElement("//scoreLogSchema").ToString());
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: