This may be a simple question but I get stuck. I want to reformat a
XML document into another XML document, with the following code:
...
Source xmlSource = new DOMSource(xmlDoc);
Source xslSource = new StreamSource(ssURL.openStream());
Result result = new DOMResult();
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(xslSource);
transformer.transform(xmlSource, result);
...
at the last line running the transform() method, I get the exception
attached at the bottom.
seems if I use a streamResult instead of a DOMResult, there will be no
such problem. So I guess it is the root of DOMSource and DOMResult
having conflict?
Please advice. Many thanks
George
my exception:
javax.xml.transform.TransformerException: Can't have more than one
root on a DOM
!
at org.apache.xalan.transformer.TransformerImpl.transformNode(Transforme
rImpl.java:1269)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImp
l.java:504)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImp
l.java:1174)
at hgc.lib.structs.taglib.list.ReportItemsTag.doEndTag(ReportItemsTag.ja
va:89)
at _0002finMilestoneListing_0002ejspinMilestoneListing_jsp_17._jspServic
e(_0002finMilestoneListing_0002ejspinMilestoneListing_jsp_17.java:279)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
...
> hi all,
>
> This may be a simple question but I get stuck. I want to reformat a
> XML document into another XML document, with the following code:
>
> ...
> Source xmlSource = new DOMSource(xmlDoc);
> Source xslSource = new StreamSource(ssURL.openStream());
> Result result = new DOMResult();
>
> TransformerFactory factory = TransformerFactory.newInstance();
> Transformer transformer = factory.newTransformer(xslSource);
> transformer.transform(xmlSource, result);
> ...
>
> at the last line running the transform() method, I get the exception
> attached at the bottom.
>
> seems if I use a streamResult instead of a DOMResult, there will be no
> such problem. So I guess it is the root of DOMSource and DOMResult
> having conflict?
>
> Please advice. Many thanks
> my exception:
>
> javax.xml.transform.TransformerException: Can't have more than one
> root on a DOM
Hello,
well, your code looks reasonable. Have you checked if your style sheet
produces valid XML? You could try to invoke Xalan with some sample data
from the command prompt and check the produced XML for errors.
HTH
<Andreas value="EUR 0.02"/>
--
/toe/ff
el@/treu/
f/uss.
de//
Yeah thanks for your suggestion. You've got the point, it's the xsl
that not generating a valid xml. Thanks a lot.
cheers
george
Andreas Wollschlaeger <postm...@1.0.0.127.in-addr.arpa> wrote in message news:<a5jt0i$oub$06$1...@news.t-online.com>...