in reply to Jointly parsing characters and entities in XML::Twig

You have it nearly right, you just have to replace char_handler by text_output_filter, and everything works OK.

I strongly suspect (I have to check) that what happens is that during the parsing, XML::Twig receives 3 events for the data element, 1 before the entity, 1 for the entity, and 1 after the entity. As of now, the char_handler is thus called 3 times, which might be considered a bug, I'll look into it. By using text_output_filter the substitution is performed later, once the 3 texts have been merged.

Does that solve your problem?

  • Comment on Re: Jointly parsing characters and entities in XML::Twig

Replies are listed 'Best First'.
Re^2: Jointly parsing characters and entities in XML::Twig
by eff_i_g (Curate) on Sep 12, 2008 at 16:56 UTC
    Or output_text_filter, rather? I was digging through that meaty POD yesterday and I obviously missed that one.

    Yes, this appears to have solved my problem. mirod, thanks for creating, maintaining, and supporting such a grand module! :)
      Or output_text_filter, rather

      Oops! The sad thing is that I did a cut'n paste. My test code did not do the replace at all, but I didn't see it ;--( I'm glad I was close enough that you managed to get it right!

      Which is why you (and by that I mean... I) should always write tests as real tests, using Test::* and comparint the expected result to the real one. That will save you embarrassment, and will prevent a few bugs every now and then.