如何在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());
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());
相关文章推荐
- 如何在XElement中使用XPath
- 如何在XElement中使用XPath
- XML学习笔记(六):如何使用XPath-基本概念
- xpath中如何使用变量
- 新版火狐浏览器如何使用Xpath语法解析网页元素。
- 如何解决FormView中实现DropDownList连动选择时出现 "Eval()、XPath() 和 Bind() 这类数据绑定方法只能在数据绑定控件的上下文中使用" 的错误
- 如何在 Watir 中使用 XPath 定位和操作页面元素
- phantomjs 中如何使用xpath
- 如何在 Watir 中使用 XPath 定位和操作页面元素
- 如何使用 XPath 表达式查询 XML
- XPath 语法(如何使用dom4j中的selectNodes函数)
- 如何在 Watir 中使用 XPath 定位和操作页面元素
- 如何解决FormView中实现DropDownList连动选择时出现 "Eval()、XPath() 和 Bind() 这类数据绑定方法只能在数据绑定控件的上下文中使用" 的错误
- Chrome如何使用xpath插件
- 【驱动使用】如何在一台PC机器上运行两个CP210X的串口
- asp.net 2.0 下如何配置使用fckeditor
- 如何自定义注解及使用
- 没有触屏如何使用键盘玩转Win8新界面
- 如何修改git commit所使用的编辑器为vim
- 如何在网站开发中使用LINQ操作数据库