DefaultHandler to generate DOM
Added by Anonymous over 14 years ago
Legacy ID: #8490658 Legacy Poster: christophe.marchand (ch-marchand)
Hi ! I have many xml files to merge into one, before writting the result. I would prefere use an XSL transform to write generated XML. So I would like my merge process generates a DOM (or any object-model) tree. Due to schema constraints, merge will be much more easy for me to write as a DefaultHandler throw I will give my differents source xml files. So I would like my handler to generate a DOM tree (to be a DOMSource for transform). Does someone have an example of a DefaultHandler that generates a DOM tree ? Thanks in advance, Christophe
Replies (2)
RE: DefaultHandler to generate DOM - Added by Anonymous over 14 years ago
Legacy ID: #8490766 Legacy Poster: Michael Kay (mhkay)
Sorry, it's not clear to me what you are asking. It sounds as if you want to merge the files on the way in to the transformation, is that right? Why do you specifically want to construct the merged document as a tree? The simplest way is to use getTransformerHandler() to get the transformer in the form of a SAX ContentHandler that you can pipe events into, and then write a SAX filter that parses each of the files in turn, passing the events transparently to the TransformerHandler. But even that seems like a lot more complexity than is justified - are you sure you can't simply use <xsl:copy-of select="collection('abc')"/> within the transformation, and avoid writing any Java code at all? If memory is an issue, saxon:discard-document() can be used to discard each document from memory once it has been written, or if the individual documents are large you could go further and use Saxon-EE streaming facilities. Merging files is usually very simple
RE: DefaultHandler to generate DOM - Added by Anonymous over 14 years ago
Legacy ID: #8490846 Legacy Poster: christophe.marchand (ch-marchand)
Well, I want to use a transform just to write my Xml : tFactory.newTransformer() - just for clean writting purpose So I would like to generate a Source for transform(...,..), and like I do not want to write the generated xml, the only Source subclass I can use is a DOMSource (all other need a Stream, so need the xml to be written) - so I need a Object-model tree. I have to look at getTransformHandler(), because I'm not axare of this... Keep tuned, I may need other help ! Thanks a lot for this, I'm gonna lookt into this. Christophe
Please register to reply