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

Y2J
Release: 2017-04-28 10:40:53
Original
1437 people have browsed it

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
Copy after login

The above is the detailed content of C#中通过xpath查找xml的指定元素的代码实例. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!