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

<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>
poj

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.