溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

C#中如何通過xpath查找xml的指定元素

發(fā)布時間:2020-07-11 15:08:47 來源:億速云 閱讀:298 作者:Leah 欄目:編程語言

本篇文章為大家展示了C#中如何通過xpath查找xml的指定元素,代碼簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。

orders.xml文檔內(nèi)容如下
<?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

上述內(nèi)容就是C#中如何通過xpath查找xml的指定元素,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注億速云行業(yè)資訊頻道。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI