Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Search and replace in portion of xml file

by toolic (Bishop)
on Jun 01, 2009 at 12:04 UTC ( #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: (4)
As of 2023-12-08 19:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (37 votes). Check out past polls.

    Notices?