Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Search and replace in portion of xml file

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


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>

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2025-07-15 19:42 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.