XPathExtensions
using System.Xml.XPath;
namespace Castle.Components.DictionaryAdapter.Xml
{
public static class XPathExtensions
{
public static XPathNavigator (this IXPathNavigable source)
{
if (source == null)
throw Error.ArgumentNull("source");
return source.CreateNavigator();
}
public static bool (this XPathNavigator navigator)
{
if (!navigator.MoveToFirstChild())
return false;
while (navigator.MoveToNext()) {
}
return true;
}
public static bool (this XPathNavigator navigator)
{
if (!navigator.MoveToFirstAttribute())
return false;
while (navigator.MoveToNextAttribute()) {
}
return true;
}
public static XPathNavigator (this XPathNavigator navigator)
{
navigator = navigator.Clone();
navigator.MoveToRoot();
if (navigator.NodeType == XPathNodeType.Root && !navigator.MoveToFirstChild())
throw Error.InvalidOperation();
return navigator;
}
public static XPathNavigator (this XPathNavigator navigator)
{
navigator = navigator.Clone();
if (!navigator.MoveToParent())
throw Error.InvalidOperation();
return navigator;
}
public static void (this XPathNavigator node)
{
while (node.MoveToFirstChild()) {
node.DeleteSelf();
}
while (node.MoveToFirstAttribute()) {
node.DeleteSelf();
}
}
}
}