in reply to XML::TreeBuilder invalid token problem
Since the result of step 2 is an invalid entity reference, either step 2 should not have been done (leaving ' as-is), or the remaining ampersand should have been converted as well, to yield %26%2339; (update: or perhaps it should have been rendered as &%2339;)
The whole mess could have been avoided if the original apostrophe had been converted to %27, though I'm not sure from your description whether this would actually work either...
Another update: As for actually dealing with that, maybe you want to "pre-condition" the text before passing it to XML::TreeBuilder -- e.g. if you have the whole xml string in a scalar called "$text", you could do this:
(or be more particular/ad-hoc, and just do s/\%23/\#/g;) Then pass $text to Treebuilder. That might put things right.$text =~ s/\%([0-9A-F]{2})/chr(hex($1))/eg;
|
|---|