Sunday, August 12, 2012

Check out XFiles... ["Using XPath to Navigate the File System"]

CodeProject - Using XPath to Navigate the File System

Introduction

This article has two goals:

  1. 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
  2. It presents the new alternative way to work with files and folders that some people may consider useful

What is XPathNavigator

XPathNavigator is the system abstract class, that implements XPath document model and provides means of navigating through XML nodes, and evaluating XPath expressions. Unlike XmlNode or XNode, XPathNavigator is a cursor, that may point to any node in the XML tree and be moved to another node. XPathNavigator is also used as an input for XslCompiledTransform, and therefore any implementation of the XPathNavigator can be transformed with an XSLT stylesheet.

XPathNavigator implementations exist for all XML models in .NET, including XmlDocument and LINQ to XML. Generally an instance of an XPathNavigator inheritor can be created for classes that implement IXPathNavigable interface. This interface contains a single method - CreateNavigator. Classes XmlNode and XPathDocument (a special fast model that only provides read-only access via XPathNavigator model) implement IXPathNavigable. However this is not always the case. The newest library for working with XML - LINQ to XML - allows creation of XPathNavigator with extension methods.

It's worth mentioning that none of the system-integrated implementations of the XPathNavigator are public.

How to implement XPathNavigator

XPathNavigator contains 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:

...

SNAGHTML99d2f8a[4]

image..."

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.

1 comment:

Boris Dongarov said...

Ha-ha, just googled for my article and came across you post. Thanks, Greg