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

Elliotte Rusty Harold elharo at metalab.unc.edu
Tue Jul 30 06:02:09 PDT 2002


At 9:59 AM +0200 7/30/02, Laurent Bihanic wrote:
>The SAXException "Ill-formed XML document (multiple root elements 
>detected)" is thrown whenever SAXHandler (used by JDOMResult and 
>SAXHandler) is processing data that should be added to the current 
>element but no current element exists.
>
>This usually signals a bug in an XSLT stylesheet which leads the 
>XSLT processor to generate documents with several root elements or 
>with text or CDATA sections directly at document level.
>

An XSLT stylesheet is allowed to produce trees which do not have root 
elements. These are not well-formed XML documents, but the mere fact 
that a stylesheet produces one does not prove that the stylesheet is 
buggy. If TrAX or JDOMResult is not able to handle such results, that 
may well indicate a design flaw in TrAX or JDOMResult.

Hmmm, looking at the API docs I think this is a flaw in JDOM, not 
TrAX DOMResult and SAXResult do not assume they get a full document 
back from the transform. JDOMResult does. This is a mistaken 
assumption. Probably, the method

public Document getDocument()

should be

public List getResult()

The List would contain the result of the transformation, which might 
be a single Document object or might be several element and text 
objects, or something else. I'm not sure what internal changes might 
be required here to support this. Possibly, JDOMResult would need to 
use a different ContentHandler; not SAXHandler. SAXHandler is 
designed for parsing an input document which is known to be 
well-formed. That is not the case here.
-- 

+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
|          XML in a  Nutshell, 2nd Edition (O'Reilly, 2002)          |
|              http://www.cafeconleche.org/books/xian2/              |
|  http://www.amazon.com/exec/obidos/ISBN%3D0596002920/cafeaulaitA/  |
+----------------------------------+---------------------------------+
|  Read Cafe au Lait for Java News:  http://www.cafeaulait.org/      |
|  Read Cafe con Leche for XML News: http://www.cafeconleche.org/    |
+----------------------------------+---------------------------------+



More information about the jdom-interest mailing list