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"?>
Line1This 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 );
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"?>
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"?>
======================== no_blanks (second parser) <?xml version="1.0"?>
======================== keep_blanks (third parser) <?xml version="1.0"?>