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>