If you do not need the XML to be reformated and do not mind the empty lines left over after removing those tags, then this will be even more efficient:
use strict; use warnings; use XML::Rules; my $rules =XML::Rules->new( style => 'filter', rules => { '^dob' => 'skip', '^dobs' => 'skip', }, ); $rules->filter( *DATA ); __DATA__ <?xml version="1.0" encoding="UTF-8"?> <record category="B" editor="" entered="2000-12-04" sub-category=" +PEP" uid="7320" updated="2018-12-12"> ...
If you wanted to skip only some of the <dob> tags based on their attributes you could do something like this:
my $rules =XML::Rules->new( style => 'filter', rules => { '^dob' => sub { $_[1]{"xsi:nil"} eq "true" ? '' : 'handle'}, '^dobs' => 'skip', }, );
Jenda
Enoch was right!
Enjoy the last years of Rome.
In reply to Re: XML:twig XML wrong
by Jenda
in thread XML:twig XML wrong
by nico38100
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |