本篇文章為大家展示了C#中如何通過xpath查找xml的指定元素,代碼簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。
orders.xml文檔內容如下//該代碼片段來自于: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 Remarkable Office Supplies Electronic Protractor 42.99 Invisible Ink 200.25
上述內容就是C#中如何通過xpath查找xml的指定元素,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道。