shlomif / perl-XML-LibXML

The XML-LibXML CPAN Distribution for Processing XML using the libxml2 library
https://metacpan.org/release/XML-LibXML
Other
17 stars 35 forks source link

no_blanks option can't be undone in subsequent parser instances #88

Open ma-ssato opened 3 months ago

ma-ssato commented 3 months ago

If I create a parser instance with no_blanks, and later create another parser with keep_blanks, the second parser will ignore the keep_blanks option.

In the code example below, the first parser instance (keep_blanks) keeps blanks and the second parser instance (no_blanks) kills blanks. However, the third parser instance (keep_blanks) kills blanks, i.e., the keep_blanks option is ignored.

CODE EXAMPLE

!/usr/bin/env perl

use strict; use warnings;

use XML::LibXML 2.0210;

my $xmlstring = <<'EOM'; <?xml version="1.0"?>

Line1 This should be on a new line

EOM

my $parser1 = XML::LibXML->new( keep_blanks => 1 ); my $dom1 = $parser1->load_xml( string => $xmlstring );

my $parser2 = XML::LibXML->new( no_blanks => 1 ); my $dom2 = $parser2->load_xml( string => $xmlstring );

my $parser3 = XML::LibXML->new( keep_blanks => 1 ); my $dom3 = $parser3->load_xml( string => $xmlstring );

print "keep_blanks (first parser)\n"; print $dom1->serialize; print "========================\n"; print "no_blanks (second parser)\n"; print $dom2->serialize; print "========================\n"; print "keep_blanks (third parser)\n"; print $dom3->serialize;

1;

OUTPUT keep_blanks (first parser) <?xml version="1.0"?>

Line1 This should be on a new line

======================== no_blanks (second parser) <?xml version="1.0"?>

Line1This should be on a new line

======================== keep_blanks (third parser) <?xml version="1.0"?>

Line1This should be on a new line
ma-ssato commented 3 months ago

Sorry, formatting was messed up. Here's the code again. code.txt