Skip Menu |

This queue is for tickets about the XML-Twig CPAN distribution.

Report information
The Basics
Id: 8830
Status: resolved
Priority: 0/
Queue: XML-Twig

People
Owner: Nobody in particular
Requestors: stolen-from-cpan-rt [...] l2g.to
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 3.15
Fixed in: 3.16



Subject: XML-Twig-3.15: $twig->simplify dies when an element has mixed content
If XML::Twig parses an XML tree where an element has mixed content (both character content and a child element), calling the "simplify" method causes it to die with this error: Can't use string ("...") as a HASH ref while "strict refs" in use at /usr/share/perl5/XML/Twig.pm line 5617. The string in quotes varies depending on the content of the XML being parsed. Perl: 5.8.4 (i386-linux-thread-multi) Linux: 2.6.6-1-686 #1 Wed May 12 14:57:57 EST 2004 i686 GNU/Linux Some test files that can be used to (hopefully) reproduce the bug... ===== xml-twig-test.pl ===== #! /usr/bin/perl use Data::Dumper; use XML::Twig; my $test_file = "xml-twig-test.xml"; my $twig = new XML::Twig; $twig->parsefile($test_file); print Dumper($twig->simplify); ===== xml-twig-test.xml ===== <?xml version="1.0"?> <xmltwigtest> <test> <basic>This is just basic character content.</basic> </test> <test> <mixed>This is character content <i>with</i> something extra.</mixed> </test> </xmltwigtest>
[guest - Fri Dec 10 17:37:25 2004]: Show quoted text
> If XML::Twig parses an XML tree where an element has mixed content > (both character content and a child element), calling the "simplify" > method causes it to die with this error:
Indeed, it's a bug, the simplest test I found was: perl -MXML::Twig -e'XML::Twig->new->parse( "<doc>text1<elt/></doc>")->root->simplify' While I work on fixing the bug, note that you can replace simplify with XMLin( $elt->sprint). Note also that using XML::Simple, and by extension simplify on mixed content will give... mixed results at best ;--( Now that I have properly tried to deflect criticism. I admit it's a bug, and I will fix it. Thanks for the report __ Mirod
[MIROD - Fri Dec 10 19:11:33 2004]: Actually, while I am working on this, do you think it would make sense to have an option to either throw out some tags, or treat the content of some tags as just text? I suspect that in your exemple you would like to get the content of <mixed>This is character content <i>with</i> something extra.</mixed> as either This is character content <i>with</i> something extra. or This is character content with something extra. XMLin would give you content => This is character content something extra. i => with __ Mirod
From: stolen-from-cpan-rt [...] l2g.to
[MIROD - Fri Dec 10 19:11:33 2004]: Show quoted text
> Note also that using XML::Simple, and by extension > simplify on mixed content will give... mixed results at best ;--(
I noticed that. But it's okay. The data I was playing with that exposed this bug isn't technically supposed to have mixed-content elements, anyway. So I have a bug report to post elsewhere, too. :-) --Larry
[guest - Fri Dec 10 19:20:44 2004]: Show quoted text
> [MIROD - Fri Dec 10 19:11:33 2004]: >
> > Note also that using XML::Simple, and by extension > > simplify on mixed content will give... mixed results at best ;--(
> > I noticed that. But it's okay. The data I was playing with that > exposed this bug isn't technically supposed to have mixed-content > elements, anyway. So I have a bug report to post elsewhere, too. :-)
The version on my website (http://www.xmltwig.com/xmltwig/) behaves a little better. At least it doesn't die. But it gives you the content of the included tag twice: perl -MYAML -MXML::Twig -e'print Dump( XML::Twig->new->parse( "<doc><elt>text1 <i>ital</i></elt></doc>")->root->simplify)' --- #YAML:1.0 elt: content: text1 ital i: ital This could be considered a feature if it wasn't incompatible with XML::Simple ;--) I'll have an other look at it this week-end. I just hope that your other bug report gets closed before I have to close this one ;--) __ Mirod