Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

How to convert <,&,>,",' into XML &lt;,&amp;,&gt;,&quot ..

by gasho (Beadle)
on Dec 16, 2008 at 20:09 UTC ( [id://730726]=perlquestion: print w/replies, xml ) Need Help??

gasho has asked for the wisdom of the Perl Monks concerning the following question:

Dear perl monks is there a perl module that can convert: <,&,>,",' into XML <,&,>," .. Thanks
$xml_native='<message>Hello World</message>'; $xml_converted->$xml_native; print "$xml_converted" #prints &lt;message&gt;Hello World&lt;/message&gt;
(: Life is short enjoy it :)

Replies are listed 'Best First'.
Re: How to convert <,&,>,",' into XML &lt;,&amp;,&gt;,&quot ..
by ikegami (Patriarch) on Dec 16, 2008 at 20:20 UTC
    encode_entities($input, q{<>&"'}) from HTML::Entities will do the trick.
Re: How to convert <,&,>,",' into XML &lt;,&amp;,&gt;,&quot ..
by ccn (Vicar) on Dec 16, 2008 at 20:24 UTC

    May be the following conversion will satisfy you

    $xml_native =~ s/([^\w\s])/'&#'.ord($1).';'/ge;
Re: How to convert <,&,>,",' into XML &lt;,&amp;,&gt;,&quot ..
by ikegami (Patriarch) on Dec 16, 2008 at 20:21 UTC
Re: How to convert <,&,>,",' into XML &lt;,&amp;,&gt;,&quot ..
by zwon (Abbot) on Dec 16, 2008 at 20:20 UTC
      That doesn't encode.

Log In?
Username:
Password:

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

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

    No recent polls found