XmlDocument.SelectSingleNode : XmlDocument « System.Xml « C# / C Sharp by API






XmlDocument.SelectSingleNode

 

using System;
using System.Xml;
using System.Xml.XPath;

public class XPathQuery {

  public static void Main(string [] args) {

    string filename = "inventory.xml";
    string xpathExpression = "//inventory/items";

    XmlDocument document = new XmlDocument( );
    document.Load(filename);

    XmlTextWriter writer = new XmlTextWriter(Console.Out);
    writer.Formatting = Formatting.Indented;

    XmlNode node = document.SelectSingleNode(xpathExpression);
    node.WriteTo(writer);

    writer.Close( );
  }
}

   
  








Related examples in the same category

1.new XmlDocument()
2.XmlDocument.AppendChild(XmlNode docNode)
3.XmlDocument.CreateComment(String comments)
4.XmlDocument.CreateElement
5.XmlDocument.CreateXmlDeclaration
6.XmlDocument.LoadXml(String xmlString)
7.XmlDocument.Save()
8.XmlDocument.SelectNodes