Bug in XML::DOM::toString()?

V

vmontressor

XML::DOM does not XML-escape text nodes' content on output. E.g., the
command

% perl -MXML::DOM -e 'print new
XML::DOM::parser()->parse("<foo>&gt;</foo>")->toString()'

prints

<foo>></foo>

and not, as I would like and expect,

<foo>&gt;</foo>

Is there an easy way to simply XML-escape the content of all text
nodes, or something like that? (I can write a sub to do this myself, I
just figured there must be code for it already.)

It seems to do the right thing with attributes, BTW.
 
V

vmontressor

Hmm, Google Groups seems to interpret that inline XML text differently
than I expected, too (looked fine in preview). Let me try again. In
case this second try doesn't come out properly either, what I'm trying
to show is that the greater-than sign, the only text content of the foo
element, is written in escaped form in the embedded XML text in the
perl script (i.e., ampersand g t semicolon), but when it's printed by
XML::DOM, out comes just a plain greater-than sign (so XML::DOM is
writing malformed XML). What I want is for the escaped form (ampersand
g t semicolon) to be written as the content of the foo node.

Second try at my original post:

XML::DOM does not XML-escape text nodes' content on output. E.g., the
command

% perl -MXML::DOM -e 'print new
XML::DOM::parser()->parse("<foo>&amp;&gt;</foo>")->toString()'

prints

<foo>></foo>

and not, as I would like and expect,

<foo>&amp;&gt;</foo>

Is there an easy way to simply XML-escape the content of all text
nodes, or something like that? (I can write a sub to do this myself, I
just figured there must be code for it already.)

It seems to do the right thing with attributes, BTW.
 
B

Brian McCauley

% perl -MXML::DOM -e 'print new
XML::DOM::parser()->parse("<foo>&amp;&gt;</foo>")->toString()'

prints

<foo>></foo>

and not, as I would like and expect,

<foo>&amp;&gt;</foo>

I get the expected output with XML::DOM 1.43. What version of XML::DOM
are you using?
 
V

vmontressor

Brian said:
I get the expected output with XML::DOM 1.43. What version of XML::DOM
are you using?

I was using 1.27, which is the version included with Fedora Core 3. (I
assumed FC3 would be using the latest versions of everything, or anyway
closer than this.)

I just tried 1.44 (which happened to be what I got when I told CPAN to
"install XML::DOM") and that worked. Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
VetaMcRae
Top