[jdom-interest] JDOMResult silently absorbs document fragments (was: Re: [jdom-interest] Question about JDOMResult and usage with XMLReader)

manos laliotis laliotis at eml.cc
Wed Aug 14 20:11:10 PDT 2002

I was recently bitten by the same condition, wasting a number of hours before realizing what's the root of the problem. I understand the difficulties mentioned by Laurent and since apparently there's no good solution about them I would suggest to have JDOMResult throw an exception or something when document fragments (-not a full document) are encountered. Currently, in the presence of multiple document fragments, JDOMResult.getDocument() returns only the most recently-encountered fragment, without ever informing the caller that something went wrong.


Laurent Bihanic wrote:
> Elliotte Rusty Harold wrote:
>> 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.
> DOMResult can indeed return a DocumentFrangment but I do not agree with 
> you for SAXResult: It is configured with a ContentHandler and the 
> javadoc for ContentHandler states: "Receive notification of the logical 
> content of *a* document". Thus, SAXResults should not accept document 
> fragments and JDOMResult extends SAXResult.
>  > 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.
> That could be done by subclassing SAXHandler and having a pre-allocated 
> dummy root element. The main problem would then be to decide what the 
> result actually is: If the transformation returns a list of node, no 
> problem; but if a single element iss returned, should we return a 
> Document or an Element? Is there something in the XSLT spec to help 
> distinguish between these 2 cases?
> Laurent
> _______________________________________________
> 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