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
In reply to XML::LibXML unbindNode leaves blank lines in the xml file by anadem
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |