Home  >  Article  >  Backend Development  >  Code example for finding specified elements of xml through xpath in C#

Code example for finding specified elements of xml through xpath in C#

Y2J
Y2JOriginal
2017-04-28 10:40:531451browse

orders.xml文档内容如下


  
    Remarkable Office Supplies
  
  
  
    
      Electronic Protractor
      42.99
    
    
      Invisible Ink
      200.25
    
  

 
 
 
//该代码片段来自于: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

The above is the detailed content of Code example for finding specified elements of xml through xpath in C#. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn