Here is another way, using XML::Simple, which changes a few of the opponents, like you wanted.
use strict; use XML::Simple; my @data = (<DATA>); my $xml = XMLin((join'', @data)); foreach my $foo (@{$xml->{'foo'}}) { foreach my $opponent (@{$foo->{'opponent'}}) { if($opponent eq 'wolf') { $opponent = 'Heinz Sielmann'; } elsif($opponent eq 'ant') { $opponent = 'Peter Scott'; } } } print XMLout($xml, rootname => 'xml'); __DATA__ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xml> <xml> <foo class="life or death"> <opponent>wolf</opponent> <opponent>ant</opponent> </foo> <foo class="life or death"> <opponent>pantomime goose</opponent> <opponent>Terrance Rattigan</opponent> </foo> </xml>
I don't usually code a lot of XML, but when I need to, I find that XML::Simple (together with Data::Dumper) often lets me do simple stuff really quickly. Of course, it takes a little tounge-in-cheek for the dereferencing sometimes, see references quick reference for an excellent tutorial on this. :)
You have moved into a dark place.
It is pitch black. You are likely to be eaten by a wolf.

In reply to Re: Re: (jeffa) Re: XML Search and Replace by Dog and Pony
in thread XML Search and Replace by coreolyn

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.