[jdom-interest] java.lang.IllegalStateException
Laurent Bihanic
laurent.bihanic at atosorigin.com
Mon Oct 14 02:43:50 PDT 2002
Hi,
Your XPath expression does not select a single Element. Hence JDOMResult can't
create a well-formed XML document from the selected node(s) and thus returns
an empty document.
This is a well-known flaw in both JDOMSource and JDOMResult : They should not
require Documents as input/output but rather a list of nodes as specified by
XSLT 1.0. A patch has been submitted and should be committed shortly (I hope).
As for using XPath, for efficiency reasons, you should either directly use the
Jaxen XPath engine (www.jaxen.org) which support JDOM or JDOM XPath classes
(which rely on Jaxen) you can get from CVS.
Laurent
Robert Douglass wrote:
> Hello JDOM list,
>
> I'm getting the following error
>
> java.lang.IllegalStateException: Root element not set
> at org.jdom.Document.getContent(Document.java:332)
> at org.jdom.output.XMLOutputter.output(XMLOutputter.java:794)
> at org.jdom.output.XMLOutputter.output(XMLOutputter.java:585)
> at sbpgames.util.XmlUtil.applyXPath(XmlUtil.java:39)
> at sbpgames.util.XmlUtil.main(XmlUtil.java:128)
>
> when I attempt to use XMLOutputter.output on a document that is a result of
> an in memory Transformer transformation. The main method (at the bottom)
> creates a Document and passes that, along with an XPath expression as a
> String to applyXPath (first method in the class). applyXPath creates a xsl
> document that matches / and selects the XPath expression fed to it. This
> stylesheet and the xml document are then fed to transform(JDOMSource in,
> Source stylesheet, which returns a Document. If I change this line in the
> transform method
>
> JDOMResult out = new JDOMResult();
>
> to
>
> Result out = new StreamResult(System.out);
>
> then I see that the transformation is working as expected. Therefore, I
> suspect that I don't understand what happens to out in
> transformer.transform(in, out);
>
> I'm new to this technology, so I realize my error could be anywhere, and
> that this is a long chunk of code. Therefore I am very grateful to anybody
> who has the time to look at it.
>
> -Robert Douglass
More information about the jdom-interest
mailing list