You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Maurer, Kevin" <km...@microstrategy.com> on 2001/02/26 17:26:09 UTC
XSL processing problem : DOM 006 Hierarchy request error
Hello,
I have attached a short piece of code, which parses an xml string
with an xsl stylesheet, and outputs a DOM document using Xalan 2.0. The
issue is that it throws a DOM006 Hierarchy request error when I run it.
Right now, the attached code uses the following objects as the input/output
arguments to the Transformer.transform method:
StreamSource source = new StreamSource(new
StringReader(xmlStr));
DOMResult result = new DOMResult();
If I instead, parse the source first and pass in a DOMSource
containing the same string, the exception is not thrown. Similarly, if I
change the DOMResult to a StreamResult which writes to a StringWriter, the
exception is not thrown as well.
Is this a bug, or am I misusing the JAXP/TRaX interfaces?
The code is attached, along with the stack trace which results.
Thanks,
Kevin
<<test4.java>>
javax.xml.transform.TransformerException: DOM006 Hierarchy request error
at
org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.j
ava, Compiled Code)
at
org.apache.xalan.transformer.TransformerImpl.run(TransformerImpl.java:2894)
at java.lang.Thread.run(Thread.java:479)
---------
org.w3c.dom.DOMException: DOM006 Hierarchy request error
at
org.apache.xerces.dom.ParentNode.internalInsertBefore(ParentNode.java,
Compiled Code)
at
org.apache.xerces.dom.ParentNode.insertBefore(ParentNode.java:306)
at
org.apache.xerces.dom.DocumentImpl.insertBefore(DocumentImpl.java:347)
at org.apache.xerces.dom.NodeImpl.appendChild(NodeImpl.java:212)
at org.apache.xml.utils.DOMBuilder.append(DOMBuilder.java:172)
at org.apache.xml.utils.DOMBuilder.characters(DOMBuilder.java:432)
at
org.apache.xalan.transformer.ResultTreeHandler.characters(ResultTreeHandler.
java:446)
at
org.apache.xalan.stree.AttrImpl.dispatchCharactersEvent(AttrImpl.java:312)
at
org.apache.xalan.templates.ElemValueOf.execute(ElemValueOf.java:279)
at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(Transform
erImpl.java, Compiled Code)
at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(Transform
erImpl.java:2097)
at
org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(Transformer
Impl.java:2029)
at
org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.j
ava, Compiled Code)
at
org.apache.xalan.transformer.TransformerImpl.run(TransformerImpl.java:2894)
at java.lang.Thread.run(Thread.java:479)
-----
Kevin Maurer
Software Design Engineer
MicroStrategy 7 SDK Team
-----
Phone: (703) 744-6252
Email: kmaurer@microstrategy.com
Web: http://www.microstrategy.com
Re: XSL processing problem : DOM 006 Hierarchy request error
Posted by Gary L Peskin <ga...@firstech.com>.
> "Maurer, Kevin" wrote:
>
> Hello,
>
> I have attached a short piece of code, which parses an xml
> string with an xsl stylesheet, and outputs a DOM document using Xalan
> 2.0. The issue is that it throws a DOM006 Hierarchy request error
> when I run it. Right now, the attached code uses the following
> objects as the input/output arguments to the Transformer.transform
> method:
>
> StreamSource source = new StreamSource(new
> StringReader(xmlStr));
> DOMResult result = new DOMResult();
>
> If I instead, parse the source first and pass in a DOMSource
> containing the same string, the exception is not thrown. Similarly,
> if I change the DOMResult to a StreamResult which writes to a
> StringWriter, the exception is not thrown as well.
>
> Is this a bug, or am I misusing the JAXP/TRaX interfaces?
Kevin --
The problem is that the DOM requires that the children of the Document
node can only be Element (maximum of one -- also called the Document
Element), Processing Instruction, Comment, and DocumentType (also a
maximum of one). This is required for a well formed DOM tree.
You are trying to add as a child of the Document node, a text node,
namely "CCCCFFFFFFFFFFFFFFFFFFFFFFFFFFFF". However, this is not allowed
by the DOM model.
This is in contrast to the XSLT Data Model which explicitly allows text
node children as children of the Root Node
(http://www.w3.org/TR/xslt.html#root-node-children). This is why things
worked with the StreamResult, which serializes the XSLT tree, but don't
work when you want to have a DOMResult which is subject to the DOM
constraints.
This disparity between the DOM data model and the XSLT data model can
get confusing at times like these!
HTH,
Gary