Project

Profile

Help

Driving Saxon-CE from GWT

Added by William Gallafent about 6 years ago

Hi All,

I'm currently working on a web application project built using GWT.

I need to do some light extraction of data from an XML document. The only approach that I can see available in GWT's core library is direct access to the DOM, which isn't ideal. I'm therefore looking for a more comfortable way, which in the first instance would be to use XPath to extract the data.

Since Saxon-CE is built from Java sources, compiled with GWT's compiler, I'm hoping that it will be possible in some way to call Saxon directly from GWT code, rather than making calls into JavaScript to Saxon-CE's JavaScript API.

At the moment, I'm just looking at making a few XPath queries. I'd like to write code along the lines of (lifted directly from the javax.xml.xpath documentation[1] for now!):

XPath xpath = XPathFactory.newInstance().newXPath();
String expression = "/widgets/widget";
InputSource inputSource = new InputSource("widgets.xml");
NodeList nodes = (NodeList) xpath.evaluate(expression, inputSource, XPathConstants.NODESET);

… where Saxon-CE would be providing me the implementation of the XPath class.

I see in Saxon's documentation[2] that the Java versions of Saxon do present this API (incidentally, is java.xml.xpath a typo, missing the x after java?).

Is something vaguely like this possible? If not at present, I wonder how straightforward it would be to get there from the existing Saxon-CE implementation[3]. Any advice and guidance welcome!

[1] http://docs.oracle.com/javase/7/docs/api/index.html?javax/xml/xpath/package-summary.html [2] http://www.saxonica.com/documentation/#!xpath-api/jaxp-xpath [3] https://github.com/Saxonica/Saxon-CE


Replies (3)

Please register to reply

RE: Driving Saxon-CE from GWT - Added by William Gallafent about 6 years ago

To immediately answer my question in the negative, it would appear that various bits of Saxon are missing from Saxon-CE: "This includes the XQuery processor, the serializer, APIs such as JAXP, XQJ, and s9api, the TinyTree tree implementation, and many other ancillary features[1].”

If that's the case, then it looks as if I won't find the necessary bits of Saxon for doing these XPath queries (since I'd be expecting (I think) to use s9api or JAXP in this context) … confirmation or correction of that would be welcome!

[1] https://github.com/Saxonica/Saxon-CE/blob/12ba3fa32efd9765164d1794b82ab283dc7aa38a/user-doc/doc/about.xml

RE: Driving Saxon-CE from GWT - Added by Michael Kay about 6 years ago

Two main points here:

(a) Although Saxon-CE does include a full XPath 2.0 engine, it doesn't provide a "public" API to the XPath engine enabling it to be easily used in a context other than XSLT. I believe that at least one user has worked around this limitation by wrapping the XPath expression in an XSLT stylesheet and executing that - although this won't always work, since XSLT always creates a new result tree rather than returning references to existing nodes.

(b) GWT works at Java source code level. So the only ways to integrate two separate GWT applications are either (i) to take the source code of both and compile the whole lot using GWT, or (ii) to call one GWT component from the other via Javascript glue.

Depending how ambitious you are, you could possibly take the source code of Saxon-CE, create an XPath API (e.g. by retrofitting code from Saxon-HE), ditch the code that's not relevant to XPath, and then integrate the resulting source code as an XPath library into your application at source level.

RE: Driving Saxon-CE from GWT - Added by William Gallafent about 6 years ago

Thanks for those useful pointers, Michael.

I was thinking that the retrofitting-from-HE route might be a viable path … unfortunately it's a bit out of scope (focus!) for the project I'm working on at the moment! It will definitely sit at the back of my mind for the future though.

Do you have a view as to which would be the path of least resistance: implementing via the JAXP route, or the s9api approach? In particular, we don't have any of javax present in GWT's JRE emulation, for example, so minimising dependency there would be a good start!

Thanks again,

    (1-3/3)

    Please register to reply