Skip Menu |

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

Report information
The Basics
Id: 50485
Status: rejected
Priority: 0/
Queue: XML-LibXML

People
Owner: Nobody in particular
Requestors: Marek.Rouchal [...] gmx.net
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 1.70
Fixed in: (no value)



Subject: XML::LibXML 1.70 gets line numbers wrong
Upgrading XML::LibXML from 1.69 to 1.70 broke some scripts here, which rely on $node->line_number to return the correct line. The configuration here: perl-5.8.8 (no threads), gcc-4.1.2, RedHat Enterprise Linux 3.0 (update 9) and Solaris 8 (Sparc), libxml2-2.6.31 (on all platforms). Please find attached an example which reproduces the problem here; just put the script and the XML in one directory and run it from there: $ ./test-libxml.pl Using XML::LibXML 1.69 Child tag on line 3 has text: This is text 1 Child tag on line 4 has text: This is text 2 $ env PERL5LIB=/home/rouchal/Perl/LibXML-1.70/lib ./test-libxml.pl Using XML::LibXML 1.70 Child tag on line 0 has text: This is text 1 Child tag on line 0 has text: This is text 2 Hope this helps to identify the root cause and fix the regression. By the way: in the script you will find commented code to use a string of XML rather than the separate test.xml file; I noticed that both versions of XML::LibXML always show "line 0" when using the string, although it has newlines (\n) in. Would it be possible to fix the line numbers when using $xml->parse_string? Many thanks for your attention, and keep up the good work! Cheers, Marek
Subject: test-libxml.pl
#!/opt/perl_5.8.8/bin/perl -w use strict; use XML::LibXML; print "Using XML::LibXML $XML::LibXML::VERSION\n"; my $xml = <<'EOT'; <?xml version="1.0" encoding="ISO-8859-1"?> <parent> <child id="1">This is text 1</child> <child id="2">This is text 2</child> </parent> EOT my $parser = XML::LibXML->new(); #my $doc = $parser->parse_string( $xml ); my $doc = $parser->parse_file( 'test.xml' ); my @childs = $doc->getElementsByTagName('child'); foreach(@childs) { print "Child tag on line ",$_->line_number," has text: ",$_->textContent,"\n"; }
Subject: test.xml
<?xml version="1.0" encoding="ISO-8859-1"?> <parent> <child id="1">This is text 1</child> <child id="2">This is text 2</child> </parent>
Hallo, thanks for the report. Actually, this is not a bug, since you are not requesting line numbers from the parser. You have to set the line_numbers parser option, e.g. using $parser->line_numbers(1); or $parser->set_option(line_numbers => 1); # only 1.70+ or XML::LibXML->load_xml(string=>$xml, line_numbers => 1); # 1.70+ That was also the reason it didn't work for parse_string in your example in 1.69 and it was a bug that you were getting line_numbers elsewhere. In 1.70 release the code related to parser options was cleaned up and as a result, in parse_file we also default to line_numbers=>0 as was intended and documented. I'm not saying I can't be persuaded to make line_numbers=>1 the default, but the current behavior is consistent with the documentation of this and also the previous releases. -- Petr On Wed Oct 14 03:19:00 2009, MAREKR wrote: Show quoted text
> Upgrading XML::LibXML from 1.69 to 1.70 broke some scripts here, which > rely on $node->line_number to return the correct line. The configuration > here: perl-5.8.8 (no threads), gcc-4.1.2, RedHat Enterprise Linux 3.0 > (update 9) and Solaris 8 (Sparc), libxml2-2.6.31 (on all platforms). > > Please find attached an example which reproduces the problem here; just > put the script and the XML in one directory and run it from there: > > $ ./test-libxml.pl > Using XML::LibXML 1.69 > Child tag on line 3 has text: This is text 1 > Child tag on line 4 has text: This is text 2 > > $ env PERL5LIB=/home/rouchal/Perl/LibXML-1.70/lib ./test-libxml.pl > Using XML::LibXML 1.70 > Child tag on line 0 has text: This is text 1 > Child tag on line 0 has text: This is text 2 > > Hope this helps to identify the root cause and fix the regression. > > By the way: in the script you will find commented code to use a string > of XML rather than the separate test.xml file; I noticed that both > versions of XML::LibXML always show "line 0" when using the string, > although it has newlines (\n) in. Would it be possible to fix the line > numbers when using $xml->parse_string? > > Many thanks for your attention, and keep up the good work! > > Cheers, > > Marek