XmlDocumentXPathExtensions
Provides extension methods for the XmlDocument and XmlNode for document navigation.
using System.Xml.XPath;
namespace System.Xml
{
public static class XmlDocumentXPathExtensions
{
private class XmlDocumentNavigable : IXPathNavigable
{
private XmlNode ;
public XmlDocumentNavigable(XmlNode n)
{
_node = n;
}
public XPathNavigator ()
{
return _node.CreateNavigator();
}
}
public static XmlNodeList SelectNodes(this XmlNode node, string xpath)
{
return node.SelectNodes(xpath);
}
public static XmlNodeList SelectNodes(this XmlNode node, string xpath, XmlNamespaceManager nsmgr)
{
return node.SelectNodes(xpath, nsmgr);
}
public static XmlNode SelectSingleNode(this XmlNode node, string xpath)
{
return node.SelectSingleNode(xpath);
}
public static XmlNode SelectSingleNode(this XmlNode node, string xpath, XmlNamespaceManager nsmgr)
{
return node.SelectSingleNode(xpath, nsmgr);
}
public static XPathNavigator (this XmlNode node)
{
return node.CreateNavigator();
}
public static IXPathNavigable (this XmlNode node)
{
return new XmlDocumentNavigable(node);
}
public static XPathNavigator (this XmlDocument document)
{
return document.CreateNavigator();
}
public static XPathNavigator (this XmlDocument document, XmlNode node)
{
return node.CreateNavigator();
}
}
}