[jdom-interest] Question about JDOMResult and usage with XMLReader

Mario Felarca gennadius at yahoo.com
Wed Jul 24 13:09:31 PDT 2002


At 02:36 PM 7/24/2002 -0500, Mario Felarca wrote:

Hello again,

Sorry about replying to my own email, but I counducted one more test and I 
wanted to share the results.

In order to test things out, I tried the following code:

SAXHandler sh = new SAXHandler();
current.setResult(new SAXResult((ContentHandler)sh));

reader.parse(jds.getInputSource);

return sh.getDocument();

This failed in the same way that JDOMResult failed, but the stack was a 
little different.

Here it is:

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.jdom.output.SAXOutputter.endDocument(SAXOutputter.java:738)
         at org.jdom.output.SAXOutputter.output(SAXOutputter.java:613)
         at 
org.jdom.transform.JDOMSource$DocumentReader.parse(JDOMSource.java:434)

I hope this helps.

Thanks,

Mario-



>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-
>
>_______________________________________________
>To control your jdom-interest membership:
>http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com




More information about the jdom-interest mailing list