Published on wayland's Computer Stuff (http://computerstuff.jdarx.info)
TreePath and XPath
By wayland
Created 2008-03-28 06:45

What advantages would XPath gain from using TreePath? There are a few:

  • Simple TreePath would provide a simpler alternative to XPath
  • If the TreePath language becomes more widely used, people will be able to learn XPath more easily because it will already be familiar.
  • If TreePath becomes more widely used (eg. in filesystem navigation), there will be a much larger pool of people contributing to and optimising it.

For those not already familiar with TreePath, see the previous article in this series, entitled "TreePath -- a universal tree navigation language [1]".

TreePath would need to be implemented both as Complex TreePath and Simple Treepath. I'll cover Complex TreePath first.

XPath/Complex TreePath

The basic process an XPath implementor would follow for Complex TreePath is:

  1. Call TreePathSetup function to attach things to hooks
  2. Call ComplexTreeFetchNodes(), passing in a Complex TreePath which just happens to be an XPath
  3. Receive a list of nodes from ComplexTreeFetchNodes()

Of course, there would be many other options available, but that's the basic outline.

It all sounds so easy :).

MEXPath/Simple TreePath

The problems with implementing Simple TreePath in conjunction with XPath are:

  1. There needs to be a way to specify whether the specification is a Complex TreePath (ie. an XPath), or a Simple TreePath (I suggest the name MEXPath -- Mild Expedient XPath)
  2. There needs to be a way of specifying the default attribute type for each node class
  3. There needs to be a way of specifying the default child type for each node class.

One possible way to address the first problem is to have a user selecting a MEXPath calls a different function than for an XPath.

The way I addressed the second and third problems when implementing something similar was to use the first attribute/element specified in the XML schema as the default attribute/child type. That may not be the best solution, but it was simple and it worked.

Assuming that the problems above have been solved, a MEXPath implementor would take the following steps:

  1. Call TreePathSetup() to attach things to hooks
  2. Call SimpleTreeFetchNodes(), passing in a Simple TreePath which just happened to be a MEXPath (which would transform it into a Complex TreePath, and pass it to ComplexTreeFetchNodes())
  3. Receive a list of nodes from SimpleTreeFetchNodes()

That also sounds quite simple.

The only drawback at the moment is that the API is undefined. But that will be addressed later in the series.


Source URL: http://computerstuff.jdarx.info/content/treepath-and-xpath

Links:
[1] http://computerstuff.jdarx.info/content/treepath-universal-tree-navigation-language