Essential XPath
JET implements the
W3C XPath 1.0 Specification, with a few minor exceptions.
Although the XPath language is rich, there are only a small part of the XPath language that is required to use most
JET tags.
XPath (and JET) assumes that it is working on a model that has a tree structure. While this
certainly include XML documents (the X in XPath), it can include many other kinds of models as well. Out of the box,
JET supports XML documents and any model that is represented by EMF.
(See
Eclipse Modeling Framework).
A major element of XPath is the path expression. These are similar to file system paths.
- An path is a series of steps separated by forward slashes (/).
- The steps are evaluated from left to right, and generally decend the model's tree as they do so.
- Each step generally identifies tree nodes by their name (although other possibilities exist).
- Steps may have an optional filter condition which is written in square brackets ([ and ]) at the end of the step.
- An initial slash (/) indicates an expression starts at the root of the model tree.
- Path expressions can also start with a variable, which is a name preceded by a dollar sign ($).
XPath also supports general mathematical, boolean and comparison expressions as well as function calls.
JET tags that use XPath expressions have common characteristics:
- Variables are defined by several JET tags - look for a
var
attribute. They may also be defined by
the
c:setVariable
tag.
- JET tags requiring a path expresion have a
select
attribute.
- JET tags requiring a boolean expression have a
test
.
- Any tag attribute may include a dynamic XPath expression - an XPath expression surrounded by braces ({ and }).
The following tutorials provide a quick introduction to XPath expressions. The first tutorial allows you to
type expressions, and see their results!