s9api - how to create xdmnode

2009-07-24
2012-10-08
  • Stephen Nell

    Stephen Nell - 2009-07-24

    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?

     
    • Stephen Nell

      Stephen Nell - 2009-07-24

      thank you both for the prompt responses... very helpful

       
    • David Lee

      David Lee - 2009-07-24

      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.

       
    • Michael Kay

      Michael Kay - 2009-07-24

      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.

       
    • Michael Kay

      Michael Kay - 2009-07-24

      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!

       

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks