in reply to Re: (jeffa) Re: XML Search and Replace
in thread XML Search and Replace
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. :)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>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: (jeffa) Re: XML Search and Replace
by IlyaM (Parson) on Jun 13, 2002 at 08:32 UTC |