C#中通过xpath查找xml的指定元素的代码实例

发布时间:2022-05-15 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了C#中通过xpath查找xml的指定元素的代码实例脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
orders.XML文档内容如下
<?XMl version="1.0"?>
<Order id="2004-01-30.195496">
  <Client id="ROS-930252034">
    <Name>Remarkable Office Supplies</Name>
  </Client>
  
  <ITems>
    <Item id="1001">
      <Name>Electronic PRotractor</Name>
      <Price>42.99</Price>
    </Item>
    <Item id="1002">
      <Name>Invisible Ink</Name>
      <Price>200.25</Price>
    </Item>
  </Items>
</Order>
 
 
 
//该代码片段来自于:www.sharejs.COM/codes/csharp/7775
   
C#代码
using System;
using System.XML;
  
public class xpathSelectNodes {
    private static void Main() {
  
        // Load the document.
        XmlDocument doc = new XmlDocument();
        doc.Load("orders.xml");
        Xmlnodelist nodes = doc.SelectNodes("/Order/Items/Item/Name");
  
        foreach (XmlNode node in nodes) {
            Console.WriteLine(node.InnerText);
        }
  
        Console.ReadLine();
    }
}
 
 
//该代码片段来自于:www.sharejs.com/codes/csharp/7775

以上就是C#中通过xpath查找xml的指定元素的代码实例的详细内容,更多请关注脚本宝典其它相关文章

脚本宝典总结

以上是脚本宝典为你收集整理的C#中通过xpath查找xml的指定元素的代码实例全部内容,希望文章能够帮你解决C#中通过xpath查找xml的指定元素的代码实例所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:C#