|more useful options|
XML::Twig handlers weirdness?by gjb (Vicar)
|on Feb 20, 2006 at 15:09 UTC||Need Help??|
gjb has asked for the
wisdom of the Perl Monks concerning the following question:
Wise Monks, I've to turn to you for a piece of advise on the following problem.
I'm using XML::Twig to parse an XML file. The output should simply be the path of each element in the DOM tree. I've written a handler that is associated to all start tags and that does precisely that. Since I don't want the leading '/', I strip it using substr. No problem so far. However, I also want to have the XML tags in lowercase and now things start to get interesting.
I've included two Perl programs, one that parses an actual XML file, the other simulating the behavior of the handler on ordinary text data to try and isolate the problem. The output of the latter seems fine, while the output of the former is clearly incorrect.
The output produced is:
Note the third group which doesn't yield the expected output. Below is the attempt to reproduce this outside the context of XML parsing:
which produces the expected results below:
It would seem that within the XML handler something very weird happens, as if a variable with a fixed length (that which it has in the first invocation) is reused between calls to the handler.
I'd be grateful if someone could shed some light on this. Thanks in advance, -gjb-
Update: given that this seems to be a version specific issue, I should mention the results above have been obtained using XML::Twig 3.23 (i.e. the latest version) on Perl 5.8.7 built for cygwin-thread-multi-64int (i.e. the standard version that can be installed using Cygwin's installer).