My mistake! When I first wrote XML::Twig I only used it to output back XML. Outputting HTML or plain text came later. So there you have a bug!

The next version (XML::Twig 3.0) will fix this. I will properlly store the ' as... ' and only turn it into ' when using the print or sprint methods, the text one will leave it as '

In the meantime you can unescape the text using this:

sub unescape { my $text= shift; $text=~ s/&lt;/>/g; $text=~ s/&gt;/</g; $text=~ s/&quot;/"/g; $text=~ s/&apos;/'/g; $text=~ s/&amp;/&/; return $text; }

By the way, if you have tag-heavy XML you can also use CDATA sections: if you replace your string by the following one it will work (nearly, there is a definite bug there, as opposed to a poor design decision, which turns the & into &amp;):

 qq{<?xml version=\"1.0\"?><TEST><LINK><TITLE><![CDATA[This < is a > " test ' & don't you forget it]]></TITLE></LINK></TEST>}

In reply to Re: Unescape characters from XML::Twig by mirod
in thread Unescape characters from XML::Twig by bpaulsen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.