Use SelectNodes to query nodes by XPath : XmlDocument « XML « C# / C Sharp






Use SelectNodes to query nodes by XPath

   

using System;
using System.Xml;

class MainClass {
    private static void Main() {
        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();
    }
}

   
    
  








Related examples in the same category

1.A Simple XML Example
2.LoadXml
3.Save, AppendChild, CreateXmlDeclaration, CreateElement
4.Call GetElementsByTagName to get an element
5.Use Load method in XmlDocument to load xml document
6.Get XML Nodes in a Specific XML Namespace
7.Find Elements with an XPath Search
8.Add XmlElement
9.Load With Includes
10.Non CData Normalize