C#通過xpath查找xml指定元素的方法
更新時間:2015年04月02日 15:06:02 作者:令狐不聰
這篇文章主要介紹了C#通過xpath查找xml指定元素的方法,涉及C#操作XML文件的技巧,非常具有實用價值,需要的朋友可以參考下
本文實例講述了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>
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(); } }
輸出結(jié)果
Electronic Protractor Invisible Ink
希望本文所述對大家的C#程序設(shè)計有所幫助。
相關(guān)文章
C#靜態(tài)代碼織入AOP組件之Rougamo的使用詳解
Rougamo是一個靜態(tài)代碼織入的AOP組件,同為AOP組件較為常用的有Castle、Autofac、AspectCore等,下面就跟隨小編一起來學習一下它的具體使用吧2024-01-01C#函數(shù)式編程中的遞歸調(diào)用之尾遞歸詳解
這篇文章主要介紹了C#函數(shù)式編程中的遞歸調(diào)用詳解,本文講解了什么是尾遞歸、尾遞歸的多種方式、尾遞歸的代碼實例等內(nèi)容,需要的朋友可以參考下2015-01-01