in reply to Unescape characters from XML::Twig

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>}

Replies are listed 'Best First'.
Re: Re: Unescape characters from XML::Twig
by nardo (Friar) on Apr 20, 2001 at 21:24 UTC
    Minor correction, the line:
    $text=~ s/&amp;/&/;
    should be:
    $text=~ s/&amp;/&/g;.