Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Search and replace in portion of xml file

by toolic (Bishop)
on Jun 01, 2009 at 22:45 UTC ( [id://767404]=note: print w/replies, xml ) Need Help??


in reply to Re: Search and replace in portion of xml file
in thread Search and replace in portion of xml file

... and I'm finally getting around to providing an example today:
use strict; use warnings; use XML::Twig; my $xmlStr = <<XML; <foo> <article>ME ME ME</article> <particle>ME TOO</particle> </foo> XML my $twig= new XML::Twig( twig_handlers => { article => \&article } ); $twig->parse($xmlStr); $twig->print(); print "\n"; exit; sub article { my ($twig, $art) = @_; my $stuff = $art->text(); # get the text of article $stuff =~ s/ME/E/g; $art->set_text($stuff); } __END__ <foo><article>E E E</article><particle>ME TOO</particle></foo>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://767404]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2025-07-13 13:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.