CodeProject - Using XPath to Navigate the File System
Introduction
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. UnlikeXmlNodeorXNode,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 forXslCompiledTransform, and therefore any implementation of theXPathNavigatorcan be transformed with an XSLT stylesheet.
XPathNavigatorimplementations exist for all XML models in .NET, includingXmlDocumentand LINQ to XML. Generally an instance of anXPathNavigatorinheritor can be created for classes that implementIXPathNavigableinterface. This interface contains a single method -CreateNavigator. ClassesXmlNodeandXPathDocument(a special fast model that only provides read-only access viaXPathNavigatormodel) implementIXPathNavigable. However this is not always the case. The newest library for working with XML - LINQ to XML - allows creation ofXPathNavigatorwith extension methods.It's worth mentioning that none of the system-integrated implementations of the
XPathNavigatorare public.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.
Ha-ha, just googled for my article and came across you post. Thanks, Greg
ReplyDelete