If you want to update a tree in situ, then the only clean way of doing it is with XQuery Update (which isn't available in HE).

XQuery Update will work on any implementation of MutableNodeInfo, of which there is currently only one: Saxon's linked tree model. This interface IS available in Saxon-HE, but the update interfaces really aren't designed to be used directly from Java, they're designed very much to underpin the XQuery update engine and don't do all the validation they ought to do in a public API.

You do of course have the option of using a mutable tree implementation like JDOM and then using Saxon over that tree model (via the appropriate wrapper interface). But this is always much more expensive than using Saxon's native tree models. (One reason the TinyTree is so efficient is that it takes advantage of being immutable).

Although doing a complete transform (that is, copying the whole document) in order to insert one node seems very wasteful, it is in some ways the cleanest approach, so my advice would be not to reject it unless you have very concrete evidence (as distinct from just a gut feel) that the performance will be unacceptable.

Michael Kay

On 3 Feb 2014, at 05:13, Rajath.Sakkari@continental-corporation.com wrote:


We are using Saxon_he for reading and writing xml documents. One requirement we encountered is to write a new xml node at a specific location.

What would be the way to insert node into already existing xml in saxon ? or to insert into specific location while writing/building a huge xml.
Some pointers to this topic would be of great help.

PS- Did a bit of search, JDom gives certain APIs to append in between nodes. But we would like to stick to Saxon rather than doing a new implementation all together.

Thanks and Regards,
Rajath Sakkari K

Continental Automotive Components (India) Private Ltd.

E-Mail:  rajath.sakkari@continental-corporation.com------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
saxon-help mailing list archived at http://saxon.markmail.org/