471,344 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,344 software developers and data experts.

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

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.

Aug 18 '05 #1
3 2360
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.

Aug 19 '05 #2
vm*********@yahoo.com wrote:
% 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?

Aug 20 '05 #3
Brian McCauley wrote:
vm*********@yahoo.com wrote:
% 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?


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!

Aug 25 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Robert M. Gary | last post: by
2 posts views Thread by Daniel Bass | last post: by
5 posts views Thread by Kevin Burton | last post: by
36 posts views Thread by Wilfredo Sánchez Vega | last post: by
1 post views Thread by ar283 | last post: by
jeffbroodwar
1 post views Thread by jeffbroodwar | last post: by
reply views Thread by Ronak mishra | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.