|JET - Only possible to use xpath? [message #16065]
||Thu, 17 May 2007 02:03
| Apls Bsaim
Registered: July 2009
I have an XML file that I would use as input to my Jet file in order to read
the XML document and generate code.
It will be similar to the examples given here:
To read an XML document from JET, is using xpath the only option?
I find xpath to be somewhat cumbersome and also I cannot get the square
brackets to work in JET.
For instance, if I say <c:get select="/AAA/BBB " /> to "select the first
BBB child of element AAA" it doesn't do that.
Is there any way I can use scriptlets <% ... %> to get the nodes and
attributes from the XML model?
I think that might be easier for me as I am generating Java code.
Thanks for the help.
|Re: JET - Only possible to use xpath? [message #16082 is a reply to message #16065]
||Thu, 17 May 2007 08:26
| Paul Elder
Registered: July 2009
First, I'd like more details on this:|
> For instance, if I say <c:get select="/AAA/BBB " /> to "select the
> first BBB child of element AAA" it doesn't do that.
Can you send me an example? If it is not working, it is definitely a bug
that must be fixed.
As for using Java code, JET supports Java scriptlets, expressions and
declarations. Here's a link to the help page:
Some useful facts for writing Java code and accessing the transformation
1) The XPath expressions work on data stored in the JET2Context passed to
the template. In Java expressions and scriptlets, this is available as the
2) The root of the source document passed to the JET (which the XPath engine
treats as /) may be obtained by context.getSource().
3) The XPath variables are stored in the context, too:
context.getVariable("...name..."). Do not include the dollar ($) sign.
4) The tricky part in writing some Java code is determining Java types
variables. JET loads XML documents using EMF's generic XML support.
Documents that have no XML Schema get loaded using the inscrutable AnyType.
If you have to write Java expressions against AnyType, I can guarantee
you'll have more code than an XPath expression.
5) If you transformation is reading a document that has a registered Ecore
model, then context.getSource() will be the EMF Resource object, and values
returned XPath expressions will be the EObjects in your model. It is much
easier to use Java expressions with such models.
Powered by FUDForum
. Page generated in 0.02562 seconds