in reply to XML:twig XML wrong
I'm a bit rusty with XML but, if I understood your request, this deletes unwanted elements
use strict; use warnings; use XML::Twig; my $twig=XML::Twig->new( twig_handlers => { 'dob' => sub{ $_->delete;}, 'dobs' => sub{ $_->delete;}, _default_ => sub{ $_[0]->flush }, }, pretty_print => 'indented', empty_tags => 'normal', ); $twig->parse( *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"> <person ssn="" e-i="E"> <title xsi:nil="true"/> <position xsi:nil="true"/> <names> <first_name/> <last_name>BA</last_name> </names> <agedata> <age xsi:nil="true"/> <as_of_date xsi:nil="true"/> <dob xsi:nil="true"/> <dobs> <dob xsi:nil="true"/> </dobs> <deceased xsi:nil="true"/> </agedata> </person> <details> <id_numbers> <id loc="INT" type="">fd</id> </id_numbers> <place_of_birth xsi:nil="true"/> <locations> <location country="df" city="re" state="">Shahrara</lo +cation> </locations> </details> </record>
The output will be:
<?xml version="1.0" encoding="UTF-8"?> <record category="B" editor="" entered="2000-12-04" sub-category="PEP" + uid="7320" updated="2018-12-12"> <person e-i="E" ssn=""> <title xsi:nil="true"/> <position xsi:nil="true"/> <names> <first_name/> <last_name>BA</last_name> </names> <agedata> <age xsi:nil="true"/> <as_of_date xsi:nil="true"/> <deceased xsi:nil="true"/> </agedata> </person> <details> <id_numbers> <id loc="INT" type="">fd</id> </id_numbers> <place_of_birth xsi:nil="true"/> <locations> <location city="re" country="df" state="">Shahrara</location> </locations> </details> </record>
L*
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: XML:twig XML wrong
by nico38100 (Novice) on Feb 01, 2019 at 10:34 UTC |