Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: XML:twig XML wrong

by Jenda (Abbot)
on Mar 20, 2019 at 00:53 UTC ( #1231467=note: print w/replies, xml ) Need Help??


in reply to XML:twig XML wrong

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1231467]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2020-06-01 17:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (5 votes). Check out past polls.

    Notices?