The goal of this project is to provide support for using the XPath language to navigate arbitrary Eclipse Modeling Framework (EMF) models. Jaxen is used as the underlying XPath engine, with a custom document model adapter that allows it to navigate EMF object graphs using XPath constructs. Because XPath works with tree-based document structures, EMF's containment hierarchy is used as the basis for the mapping:
contents(nodeset?)
function to expose a reference's (the function's argument, or taken from the
current context) contentsresources sub-element for each
Resource they containcontents sub-element for each
object they contain, as well as a text node with their URI (if non-null)eClass(nodeset?) exposes the argument's (or
current context's) metamodel
For instance, using the example Library model referenced in EMF tutorials,
XPath expression /resources/contents/lib:books would designate
all books in the library. Expression
lib:books[lib:author=current()/lib:writers[lib:name='John Grisham']]
designates those library books whose author's name is John Grisham. Note that
the lib prefix must be bound to Library's namespace. E.g.,
EMFXPath xpath = new EMFXPath("lib:books[lib:author=current()/lib:writers[lib:name='John Grisham']]");
xpath.addNamespace("lib", LibraryPackage.eNS_URI);
List books = xpath.selectNodes(library);
Note that this navigation model does not necessarily match the DOM model generated by EMF's XML persistence mechanism. In fact, the models need not be persisted in XML at all in order to be used with EMFXPath. Those who wish to evaluate XPath expressions against a literal XML representation of their EMF models should try an alternative XPath evaluator implemented in class EMFDOMXPath (experimental).
Class EMFXPath provides a helper static method dump(Object, OutputStream),
which traverses the given object, converts it to XML and writes it out into the output
stream. This is especially useful for debugging -- it essentially
shows the model from the navigator's point of view (i.e., how EMFXPath sees it). For instance,
an example Library model with two writers and three books might look like this:
<resources>
<contents>
<library:name>Test Library</library:name>
<library:writers>
<library:name>Writer 1</library:name>
<library:books>test.library#/0/@books.0</library:books>test.library#/0/@writers.0</library:writers>
<library:writers>
<library:name>Writer 2</library:name>
<library:books>test.library#/0/@books.1</library:books>
<library:books>test.library#/0/@books.2</library:books>test.library#/0/@writers.1</library:writers>
<library:books>
<library:title>Book 1</library:title>
<library:pages>1000</library:pages>
<library:category>Mystery</library:category>
<library:author>test.library#/0/@writers.0</library:author>test.library#/0/@books.0</library:books>
<library:books>
<library:title>Book 2</library:title>
<library:pages>2000</library:pages>
<library:category>ScienceFiction</library:category>
<library:author>test.library#/0/@writers.1</library:author>test.library#/0/@books.1</library:books>
<library:books>
<library:title>Book 3</library:title>
<library:pages>3000</library:pages>
<library:category>Biography</library:category>
<library:author>test.library#/0/@writers.1</library:author>test.library#/0/@books.2</library:books>test.library#/0</contents>test.library</resources>
The latest release (2.0.0) is a complete rewrite of the navigation model. It was compiled using Eclipse 3.2.1, EMF 2.2.1, and JRE 1.4.2. The latest Jaxen distribution (v1.1) is included.
| Package | Description |
|---|---|
| emf-xpath-2.0.0.zip | Binary feature |
| emf-xpath-SDK-2.0.0.zip | SDK feature with source and unit tests |
Alternatively, you can point your Eclipse Update Manager to this project's update site at http://www.eclipticalsoftware.com/updates.
This software is made available under the terms of the Eclipse Public License v1.0.