Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^4: & and XML::Simple

by Anonymous Monk
on Jun 08, 2017 at 01:57 UTC ( [id://1192322]=note: print w/replies, xml ) Need Help??


in reply to Re^3: & and XML::Simple
in thread & and XML::Simple

The "correct way to fix it" is to use an XML building module that automatically escapes things for you.
use strict; use warnings; use XML::Simple qw( :strict ); my $xml = '<foo><bar>blah&amp;blah</bar></foo>'; my @opts = (KeepRoot=>1, KeyAttr=>[]); my $data = XMLin($xml, ForceArray=>1, @opts); use Data::Dump; dd($data); print(XMLout($data, @opts));
Output:
{ foo => [{ bar => ["blah&blah"] }] } <foo> <bar>blah&amp;blah</bar> </foo>
Note that the ampersand is unescaped in the first output line, then escaped again in the XML.

Also, don't use XML::Simple. Someone want to suggest a better module?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1192322]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-19 19:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found