I'm not sure I understand you right, but if you wanted to be able to remove or copy a <listView> (including contents) based on the value of the <name> tag you might do something like this:

use strict; use warnings; no warnings 'uninitialized'; use Storable qw(dclone); use XML::Rules; my $parser =XML::Rules->new( style => 'filter', start_rules => { views => sub { if (exists $_[4]->{parameters}{remove}) { if (ref($_[4]->{parameters}{remove}) eq 'ARRAY') { my %tmp; @tmp{@{$_[4]->{parameters}{remove}}} = (); $_[4]->{parameters}{remove} = \%tmp; } elsif (ref($_[4]->{parameters}{remove}) ne 'HASH') +{ die "The remove parameter must be either a HASH or + ARRAY reference!\n"; }; } if (exists $_[4]->{parameters}{copy} and ref($_[4]->{param +eters}{copy}) ne 'HASH') { die "The copy parameter must be either a HASH or ARRAY + reference!\n"; } 1; } }, rules => { _default => 'raw extended', listView => sub { my $name = $_[1]->{':name'}{_content}; if (exists $_[4]->{parameters}{copy}{$name}) { if (exists $_[4]->{parameters}{remove}{$name}) { # rename $_[1]->{':name'}{_content} = $_[4]->{parameters}{c +opy}{$name}; return $_[0] => $_[1]; } else { # copy my $copy = dclone($_[1]); $copy->{':name'}{_content} = $_[4]->{parameters}{c +opy}{$name}; # return $_[0] => $_[1], $_[0] => $copy; return [ [$_[0] => $_[1]], "\n ", [$_[0] => $co +py]]; } } elsif (exists $_[4]->{parameters}{remove}{$name}) { # remove return; } else { # nothing return $_[0] => $_[1]; } }, } ); $parser->filter(\*DATA, \*STDOUT, { # remove => [qw(Tab1)], copy => {Tab1 => 'NeTab'} }); __DATA__ <hudson> <views> <listView> <owner reference="../../.."/> <jobNames class="tree-set"> <comparator class="hudson.util.CaseInsensitiveComparator"/> <string>zip</string> </jobNames> <name>Tab1</name> </listView> <listView> <owner reference="../../.."/> <jobNames class="tree-set"> <comparator class="hudson.util.CaseInsensitiveComparator" refe +rence="../../../listView/jobNames/comparator"/> <string>zip1</string> </jobNames> <name>Tab2</name> </listView> <listView> <owner reference="../../.."/> <jobNames class="tree-set"> <comparator class="hudson.util.CaseInsensitiveComparator" refe +rence="../../../listView/jobNames/comparator"/> <string>zip</string> <string>zip1</string> </jobNames> <name>Tab3</name> </listView> </views> <slaveAgentPort>0</slaveAgentPort> <secretKey>6afc684a9a6f353335bd0f68beccc999f3adc88cac</secretKey> </hudson>

In reply to Re: Removing and Appending to an XML file by Jenda
in thread Removing and Appending to an XML file by payam77

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.