This article has two goals:
- It shows how to make your own XPathNavigator implementation and use it to evaluate XPath expressions and apply XSLT transformation to the structures, not intended to be used this way
- It presents the new alternative way to work with files and folders that some people may consider useful
What is XPathNavigator
XPathNavigatoris the system abstract class, that implements XPath document model and provides means of navigating through XML nodes, and evaluating XPath expressions. Unlike
XPathNavigatoris a cursor, that may point to any node in the XML tree and be moved to another node.
XPathNavigatoris also used as an input for
XslCompiledTransform, and therefore any implementation of the
XPathNavigatorcan be transformed with an XSLT stylesheet.
XPathNavigatorimplementations exist for all XML models in .NET, including
XmlDocumentand LINQ to XML. Generally an instance of an
XPathNavigatorinheritor can be created for classes that implement
IXPathNavigableinterface. This interface contains a single method -
XPathDocument(a special fast model that only provides read-only access via
IXPathNavigable. However this is not always the case. The newest library for working with XML - LINQ to XML - allows creation of
XPathNavigatorwith extension methods.
It's worth mentioning that none of the system-integrated implementations of the
How to implement XPathNavigator
XPathNavigatorcontains 116 public members, 112 of which can be overridden. Good news that only 20 of them are abstract, i.e. must be implemented.
Here they are:
When I first saw this I wasn't sure if it was insane or inspired. I'm still not sure about that, but I am sure that I think this is pretty awesome.