Project

Profile

Help

emit TinyTree to file??

Added by Anonymous almost 19 years ago

Legacy ID: #3184190 Legacy Poster: brud923 (berndrudolph)

Hi there, I'm doing XQueries with Saxon and really enjoy it! But I have one problem: The queries are going against a 25MB XML-File. When I'm building the TinyTree e.g.: DocumentInfo docInfo = staticContext.buildDocument(new StreamSource(new File("MAV.xml"))); it takes about 10 seconds, which is too long for my purposes. So my idea was too emit the DocumentInfo, that is built to a file, so that I can directly load the TinyTree from there. This way I would have a better performance and my data would be encrypted, as the output may be binary (not really sure about that)?! I tried to save the TinyTree using the copy method of the DocumentInfo class but I always get a NullPointerException! Here some code to give you an idea of what I'm trying to do: DOMEmitter emitDoc = new DOMEmitter(); emitDoc.setWriter(new FileWriter(new File("DOMOutput"))); docInfo.copy(emitDoc,ALL_NAMESPACES,true,1); The Exception: java.lang.NullPointerException at net.sf.saxon.dom.DOMEmitter.startElement(DOMEmitter.java:48) at net.sf.saxon.tinytree.TinyElementImpl.copy(TinyElementImpl.java:191) at net.sf.saxon.tinytree.TinyDocumentImpl.copy(TinyDocumentImpl.java:925 Could anyone please tell me what I'm doing wrong or if there's any other possibility to emit the TinyTree to a file so that I get a better performance?? Thanks Bernd


Replies (1)

RE: emit TinyTree to file?? - Added by Anonymous almost 19 years ago

Legacy ID: #3184274 Legacy Poster: Michael Kay (mhkay)

Firstly, a DOMEmitter copies the tree to a DOM, not to a file. To write to a file, you want an XMLEmitter. Secondly, all these class require some initialization. It's therefore best not to create them directly, but rather using the method ResultWrapper.getReceiver(). In fact, the cleanest way to serialize a TinyTree as XML is Transformer t = TransformerFactory.newTransformer(); t.transform(tree, new StreamResult(writer)); However, we need to look at what you are trying to achieve. If you serialize the TinyTree as XML, then next time you want it, you're going to have to parse that XML and rebuild the tree, so what have you saved? It's very possible one could devise a serialization of the tree that faster to reconstitute than the XML serialization. This needs a little care, however, because of the dependency on the name pool: if the tree is deserialized under a different configuration then all the name codes will change. Michael Kay

    (1-1/1)

    Please register to reply