[jdom-interest] Question about JDOMResult and usage with XMLReader
Mario Felarca
gennadius at yahoo.com
Wed Jul 24 12:36:36 PDT 2002
Hello all,
I have searched the archives, and have also compiled my own jar from the
latest tree, but I am experiencing some weird behavior and I was hoping
someone else may know what is causing this problem.
I have some code that is transforming data. I have an XMLReader that is
setting an ContentHandler from a templates object as its content handler.
The handler to that is being set as one of two things (since I was testing
both).
The first case, which doesn't work, is when I do the following.
JDOMResult jdr = new JDOMResult();
current.setResult(jdr);
reader.parse(jds.getInputSource());
Where current is the content handler for a templates object and reader is
the XMLReader.
This throws me the following exception on the reader.parse line.
java.lang.RuntimeException: org.xml.sax.SAXException: Ill-formed XML
document (multiple root elements detected)
at org.apache.xalan.transformer.TransformerImpl.run(TransformerImpl.java:3392)
at
org.apache.xalan.transformer.TransformerHandlerImpl.endDocument(TransformerHandlerImpl.java:433)
at org.apache.xerces.parsers.AbstractSAXParser.endDocument(Unknown Source)
at org.apache.xerces.impl.XMLNamespaceBinder.endDocument(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.endDocument(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl.endEntity(Unknown Source)
at org.apache.xerces.impl.XMLEntityManager.endEntity(Unknown Source)
at org.apache.xerces.impl.XMLEntityManager$EntityScanner.load(Unknown Source)
at
org.apache.xerces.impl.XMLEntityManager$EntityScanner.skipSpaces(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentScannerImpl$TrailingMiscDispatcher.dispatch(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
On the other hand, if I don't use JDOMResult, and instead do the following:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Serializer serial =
SerializerFactory.getSerializer(OutputProperties.getDefaultMethodProperties("xml"));
serial.setOutputStream((OutputStream)baos);
((SerializerToXML)serial).m_shouldNotWriteXMLHeader = true;
current.setResult(new SAXResult(serial.asContentHandler()));
reader.parse(jds.getInputSource());
This works if I then build a JDOMDocument using a SAXBuilder from the byte
array that I get back.
My question I guess is two-fold. First, why does the JDOMResult not work in
this case? Second, am I really losing any performance (either memory or
time/processing) by going to a byte-array and then to a JDOM Document in
two steps, as opposed to just doing a getDocument() from a JDOMResult instance?
Any thoughts or ideas would be greatly appreciated.
Thanks in advance,
Mario-
More information about the jdom-interest
mailing list