如何在XElement中使用XPath
2010-03-29 14:20
134 查看
在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
- 如何解决FormView中实现DropDownList连动选择时出现 "Eval()、XPath() 和 Bind() 这类数据绑定方法只能在数据绑定控件的上下文中使用" 的错误
- xpath中如何使用变量
- 如何在 Watir 中使用 XPath 定位和操作页面元素
- 如何使用 XPath 表达式查询 XML
- 新版火狐浏览器如何使用Xpath语法解析网页元素。
- 如何在 Watir 中使用 XPath 定位和操作页面元素
- 如何在 Watir 中使用 XPath 定位和操作页面元素
- XPath 语法(如何使用dom4j中的selectNodes函数)
- Chrome如何使用xpath插件
- 如何解决FormView中实现DropDownList连动选择时出现 "Eval()、XPath() 和 Bind() 这类数据绑定方法只能在数据绑定控件的上下文中使用" 的错误
- XML学习笔记(六):如何使用XPath-基本概念
- phantomjs 中如何使用xpath
- linux下如何使用sftp命令进行文件上传和下载
- openstack中如何使用远程连接mysql
- Android客户端和服务端如何使用Token和Session
- android如何使用url来播放音乐
- 如何使用三态工作流(一)
- 如何使用远程光盘在Mac或Windows上共享DVD/CD