Using JET Transformations with XML Documents
By default, JET transformations expect an XML documents as
input. XML documents are loaded into memory using the Eclipse
Modeling Framework (EMF) XML document support.
XPath expressions against XML documents
The JET XPath processor handles XML documents according to the
XPath 1.0 specification, with the following exception:
- The XPath processor matches expressions containing
unqualified names with elements and attributes that include a
namespace prefix. XPath expressions can still determine the
namespace URI of an element or attribute via the
namespace-uri XPath function.
Details of XML Document loading
JET uses the EMF
GenericXMLResourceFactoryImpl to load XML documents. Documents are loaded
as follows:
- If the document contains an XML schema declaration, and the
Eclipse XSD feature is installed (org.eclipse.xsd), and the XSD
file can be located, then the document is loaded according to
the XSD.
- When loading with an XSD, EMF will use the Java classes
registered against the schema, if they exist. Otherwise, Dynamic
EClasses will be generated, and loaded objects will be of
type
EObject.
- If no XSD schema is supplied, or the schema cannot be located
and there are no registered EMF Java classes for the schema, then
XML elements are loaded as instances of
AnyType.
The Model loader id for XML document loading is
org.eclipse.jet.emfxml
.
Loading XML documents during transformation execution
The launch framework automatically handles the loading of EMF resources passed to a JET
Transformation as input. If required, JET templates can load other EMF-based documents
during execution.
XML documents may by loaded using the
<c:load> and
<c:loadContent> tags. The former loads a document from
an file, while the second loads the document by parsing a text
string.
The following loads the plugin.xml file from the
transformation:
<c:load url="plugin.xml"
var="pluginXML"/>
This is equivalent to:
<c:load url="plugin.xml"
urlContext="transform"
loader="org.eclipse.jet.emfxml"
var="pluginXML"/>
The following example loads the file plugin.xml from a
project 'myproject' in the Eclipse workspace.
<c:load url="myproject/plugin.xml"
urlContext="workspace"
var="pluginXML"/>
Finally, this example loads the contents of the c:loadContent
tag as an XML document:
<c:loadContent var="myDoc">
<parts>
<item sku="123" price="1.55">Widget A</item>
<item sku="456" price="2.99">Widget B</item>
</parts>
</c:loadContent>
Loading XML documents with non-standard extensions
The XML model loader is only associated with the 'xml'
file extension. To load XML documents with other extensions as XML
documents, configure the transformation as follows:
- Open the plugin.xml file in the root of the JET
transformation project.
- Click on the Extensions tab.
- Expand the org.eclipse.jet.transform element in
the All Extensions tree.
- Click on the (transform) element
- In the modelLoader field, and enter
org.eclipse.jet.emfxml
.
- In the modelExtension field, enter
xml
.