in reply to XML::Twig::flush() and html/xml entities

That's because you're using text to get the content of the element. Form the docs:

Return a string consisting of all the PCDATA and CDATA in an element, without any tags. The text is not XML-escaped: base entities such as & and < are not escaped.

What you are looking for is xml_text (Return the text of the element, encoded, without any tag.) or xml_string (returns the string for the entire element, excluding the element's tags (but nested element tags are present).

  • Comment on Re: XML::Twig::flush() and html/xml entities

Replies are listed 'Best First'.
Re^2: XML::Twig::flush() and html/xml entities
by mandarin (Hermit) on Oct 05, 2006 at 13:55 UTC
    I changed the code in line 28 to both
    my $elt_txt = $elt->xml_text;
    and
    my $elt_txt = $elt->xml_string;
    (and left anything else alone)
    but neither did work out, I still get the convertet ampersand.
    Do I have to play around with the output_filter, too?
    I must admit that I didn't quite understand how that works.

    Martin

    update: Even text in tags never touched by the section
    function is undergoing changes.

      Ooops! That will teach me to test the code before answering. Is there any reason why you use the keep_encoding option? Without it it works fine, with it, indeed the & is not escaped in the output. You should only use this option if you are dealing with non-utf8 encodings, and want all the processing to be done in the original encoding, which doesn't seem to be your case.