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 ( #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 taking refuge in the Monastery: (7)
As of 2023-12-11 19:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (41 votes). Check out past polls.

    Notices?