在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());

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
  • 2022-12-23
猜你喜欢
  • 2021-08-04
  • 2022-12-23
  • 2022-03-01
  • 2021-12-16
  • 2022-12-23
相关资源
相似解决方案