in reply to Search and replace in portion of xml file

The sensible way to modify an XML file is to use a parser, such as XML::Twig.
  • Comment on Re: Search and replace in portion of xml file

Replies are listed 'Best First'.
Re^2: Search and replace in portion of xml file
by toolic (Bishop) on Jun 01, 2009 at 22:45 UTC
    ... 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>