You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Hugo Burm <hu...@xs4all.nl> on 2003/07/23 21:54:15 UTC
Round trip with org.apache.cocoon.xml.dom.DOMUtil.node2String
I dump my DOM node with org.apache.cocoon.xml.dom.DOMUtil.node2String to a
string.
Then I try to parse this string, hoping to create a copy of the original
node, but I get a number of parser errors.
The problem is that node2String expands entities like "&" into "&". And
when I parse the resulting string, I get the errors I could wait for.
I can do a workaround myself (search and replace). But I am wondering: is
this behaviour by intention or is it a bug? If not, how can I do this round
trip more gracefully?
I have the feeling that I did miss something elementary. But I did all the
obvious things (checking the archives and trying Google).
Hugo
RE: Round trip with org.apache.cocoon.xml.dom.DOMUtil.node2String
Posted by Hugo Burm <hu...@xs4all.nl>.
> -----Original Message-----
> From: Bruno Dumon [mailto:bruno@outerthought.org]
> Sent: Thursday, July 24, 2003 11:18 AM
> To: dev@cocoon.apache.org
> Subject: Re: Round trip with
> org.apache.cocoon.xml.dom.DOMUtil.node2String
>
>
> On Wed, 2003-07-23 at 21:54, Hugo Burm wrote:
> > I dump my DOM node with
> org.apache.cocoon.xml.dom.DOMUtil.node2String to a
> > string.
> > Then I try to parse this string, hoping to create a copy of the original
> > node, but I get a number of parser errors.
> >
> > The problem is that node2String expands entities like "&"
> into "&". And
> > when I parse the resulting string, I get the errors I could wait for.
> >
> > I can do a workaround myself (search and replace). But I am
> wondering: is
> > this behaviour by intention or is it a bug? If not, how can I
> do this round
> > trip more gracefully?
> >
> > I have the feeling that I did miss something elementary. But I
> did all the
> > obvious things (checking the archives and trying Google).
> >
>
> Nope, you didn't miss anything. If you have a look at the sources you'll
> see that no escaping is done on the data.
>
> However, you're better of using an identity TransformerHandler
> transformation. There's also an utility function in Cocoon which helps
> with this: org.apache.cocoon.xml.XMLUtils.serializeNodeToXML(Node node)
>
> --
> Bruno Dumon http://outerthought.org/
> Outerthought - Open Source, Java & XML Competence Support Center
> bruno@outerthought.org bruno@apache.org
>
>
Re: Round trip with org.apache.cocoon.xml.dom.DOMUtil.node2String
Posted by Bruno Dumon <br...@outerthought.org>.
On Wed, 2003-07-23 at 21:54, Hugo Burm wrote:
> I dump my DOM node with org.apache.cocoon.xml.dom.DOMUtil.node2String to a
> string.
> Then I try to parse this string, hoping to create a copy of the original
> node, but I get a number of parser errors.
>
> The problem is that node2String expands entities like "&" into "&". And
> when I parse the resulting string, I get the errors I could wait for.
>
> I can do a workaround myself (search and replace). But I am wondering: is
> this behaviour by intention or is it a bug? If not, how can I do this round
> trip more gracefully?
>
> I have the feeling that I did miss something elementary. But I did all the
> obvious things (checking the archives and trying Google).
>
Nope, you didn't miss anything. If you have a look at the sources you'll
see that no escaping is done on the data.
However, you're better of using an identity TransformerHandler
transformation. There's also an utility function in Cocoon which helps
with this: org.apache.cocoon.xml.XMLUtils.serializeNodeToXML(Node node)
--
Bruno Dumon http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org bruno@apache.org
Re: Round trip with org.apache.cocoon.xml.dom.DOMUtil.node2String
Posted by Tony Collen <co...@umn.edu>.
Hugo Burm wrote:
> I dump my DOM node with org.apache.cocoon.xml.dom.DOMUtil.node2String to a
> string.
> Then I try to parse this string, hoping to create a copy of the original
> node, but I get a number of parser errors.
>
> The problem is that node2String expands entities like "&" into "&". And
> when I parse the resulting string, I get the errors I could wait for.
>
> I can do a workaround myself (search and replace). But I am wondering: is
> this behaviour by intention or is it a bug? If not, how can I do this round
> trip more gracefully?
>
> I have the feeling that I did miss something elementary. But I did all the
> obvious things (checking the archives and trying Google).
Hugo,
Looking at the API docs for Node, couldn't you just call cloneNode() [1]? It looks like you can set
if you want a deep copy or not.
HTH
Tony
[1] http://xml.apache.org/xerces2-j/javadocs/api/org/w3c/dom/Node.html#cloneNode(boolean)