anadem has asked for the wisdom of the Perl Monks concerning the following question:
where the input "OLDFILE" data is like this fragment:my $parser = XML::LibXML->new(); $dom = $parser->parse_file( "OLDFILE" ); for my $matrix ( $dom->findnodes( q{ //version_matrix/vm[@type='br'] + } )) { my $version = $matrix->findvalue('./release/@version'); if( $version gt $brver ) { print "discarding version_matrix for $version\n"; my $version_matrix_node = $matrix->parentNode; $version_matrix_node->unbindNode; } } my $changed = $dom->toString; my $fh; open( $fh, '>', "NEWFILE" ); print { $fh } $changed;
The output file "NEWFILE" has gaps of a couple of lines in place of the discarded nodes, like this (where the version_matrix for br 7.3.0 was unbound):<supported_version_matrix> <version_matrix> <app> <release version="10.1.e"> <fixed>125.2004</fixed> </release> </app> <vm type="br"> <release version="7.3.0"> </release> </vm> </version_matrix> <version_matrix> <app> <release version="10.1.e"> <fixed>125.2004</fixed> </release> </app> <vm type="br"> <release version="7.2.2"> </release> </vm> </version_matrix> . . . </supported_version_matrix>
The blank lines in the gaps each contain a couple of tab characters only. I think (but not 100% sure) that from an xml perspective this doesn't change the structure, but it looks bad. Am I doing something wrong, like maybe the "$matrix" child node has to be freed somehow before its parent can be unbound? Or is there an easy way to avoid it?<supported_version_matrix> <version_matrix> <app> <release version="10.1.e"> <fixed>125.2002</fixed> </release> </app>
thanks for any illumination
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::LibXML unbindNode leaves blank lines in the xml file
by tobyink (Canon) on May 16, 2014 at 10:20 UTC | |
|
Re: XML::LibXML unbindNode leaves blank lines in the xml file
by wjw (Priest) on May 16, 2014 at 03:23 UTC | |
|
Re: XML::LibXML unbindNode leaves blank lines in the xml file
by Anonymous Monk on May 16, 2014 at 03:19 UTC | |
|
Re: XML::LibXML unbindNode leaves blank lines in the xml file
by Anonymous Monk on May 21, 2014 at 04:57 UTC | |
by Anonymous Monk on Jan 25, 2017 at 10:09 UTC |