Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: XML:twig XML wrong

by Jenda (Abbot)
on Mar 20, 2019 at 00:53 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1231467]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-03-29 06:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found