http://qs1969.pair.com?node_id=730726

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.