I know how to construct a document in memory with saxon s9api, as long as I can read in the xml document from a file or other source.. but how can I dynamically create a document that does not already exist.. ( i.e. create document node, add child nodes, etc.. ) is documentbuilder.wrap(org.w3c.dom.Element) the quickest way?
thank you both for the prompt responses... very helpful
Not sure what you mean by "quickest" but that does work.
DOM is not the best architecture for creating XML documents but it does work and is prevalent.
You can also use XQuery to create nodes that S9 API can natively use.
You can also use SAX API's but thats a bit tricky because its a "pull" architecture.
Or you can use text xml in a string, then parse that string as an XML document,
for example you can use SAX or StAX or any other serializer to construct XML Text then parse it as a document.
Of the various implementations of NodeInfo, the TinyTree is not updateable by design - its efficiency comes from the fact that it can only be built sequentially by firing SAX-like events at the builder. Of course, you can do that from code if you want, provided you can send the events in the right sequence. The LinkedTree is updateable in situ since Saxon 9.1, but the update interfaces are designed specifically to support XQuery Update and not really as a user-friendly API. I would recommend creating and wrapping a XOM - it's a much more XPath-friendly model than DOM, and much more efficient; read access via Saxon is not much slower than the TinyTree.
The other thing I would mention is that if you want to create a document programmatically, it's much easier to write your code in XSLT or XQuery than in Java!
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.