Project

Profile

Help

s9api - create custom XdmNode builder

Added by Alexey Oparin over 2 years ago

Hello,

I need to transform non xml documents. For each non xml format I create a custom parser on java. It transforms non xml to xml representaion which I send to xslt transformer further. Now my parser creates a string with xml representation which saxon parses. I want to avoid double parsing and instead of xml string create XdmNode (or similar) directily which saxon can read during xslt transformation whithout parsing need. On this forum I found very old topic https://saxonica.plan.io/boards/2/topics/193 where Michael recommended creating and wrapping a XOM in similar situation.

Is there other way to create something which saxon can read directly as effective as XdmNode? I use saxon ee 10.6.

Thanks.


Replies (3)

Please register to reply

RE: s9api - create custom XdmNode builder - Added by Michael Kay over 2 years ago

I would recommend writing your custom parser as an implementation of XMLReader, so that it can be supplied to Saxon in the form of a SAXSource. Saxon will then generate its internal TinyTree representation of the document.

Alternatively in Saxon 11 (available now in C#, coming soon on Java) you can create your own implementation of the interface ActiveSource, with a deliver() method that sends parsing events to a Saxon Receiver, bypassing the rather clumsy XMLReader and SAX interfaces.

Creating an implementation of XdmNode requires a custom implementation of NodeInfo, which is a lot more work, and probably won't perform as well.

You might find useful ideas in Michael Sperberg-McQueen's presentation last week at Declarative Amsterdam:

https://declarative.amsterdam/program

RE: s9api - create custom XdmNode builder - Added by Vladimir Nesterovsky over 2 years ago

Probably it's not the newest way of solving this task but one that definitely worked for me in the past.

SaxonTransformerFactory.newTransformerHandler() returns TransformerHandler instance, which is SAX ContentHandler that can be used to generate xml.

I think with little more effort you will find how to give it to Saxon.

RE: s9api - create custom XdmNode builder - Added by Alexey Oparin over 2 years ago

Michael, thank you. With XMLReader after some reading and investigations I got what I want. Looking forward to Saxon 11 on Java. ActiveSource looks exactly what I was looking for. Also thanks for reference to ixml. It looks very interesting.

Vladimir, thank you for your suggestion. As I understood this handler is from JAXP api. I couldn't find how to use it with s9api unfortunately. As XMLReader fully solved my problem I don't see a reason to dig this way deeper.

    (1-3/3)

    Please register to reply