If you run this against your XML it will filter out the relevant tags
#!/usr/bin/perl use strict; use XML::Twig; my $input_xml = 'big.xml'; # tags to keep my $re = qr/u_application_i|u_ci_id|sys_class_name|name|ip_address/; my $twig = 'XML::Twig'->new( twig_handlers => { result => \&record }, ); open my $fh,'>','small.xml' or die "$!"; $twig->parsefile($input_xml); sub record { my ($e,$t) = @_; for ($t->children){ $_->cut unless ($_->name =~ $re); } $t->flush($fh,pretty_print => 'indented'); }
Result
poj<result> <ip_address>10.10.10.10</ip_address> <u_application_id></u_application_id> <u_display_name>lnxnmsprag27</u_display_name> <name>lnxnmsprag27</name> <u_ci_id>CI10110212</u_ci_id> <sys_class_name>cmdb_ci_linux_server</sys_class_name> </result>
In reply to Re^5: Need help with complex hash of hashes.
by poj
in thread Need help with complex hash of hashes.
by vlturner
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |