Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: How can I replace a line (tag) in an XML file?

by andal (Hermit)
on Sep 29, 2011 at 07:58 UTC ( #928486=note: print w/replies, xml ) Need Help??


in reply to How can I replace a line (tag) in an XML file?

One can also do it without any XML parser. Here's an example

my $str = <<EOF; <students> <student> <name>John</name> <id>001</id> <gpa>A</gpa> </student> <student> <name>John</name> <id>002</id> <gpa>C</gpa> </student> </students> EOF $str =~ s/<student>(.*?)<\/student>/check_record($1)/gse; print $str; sub check_record { my $rec = shift; $rec =~ s/(<gpa>\s*)C(\s*<\/gpa>)/$1B$2/ if($rec =~ /<id>\s*002\s* +<\/id>/); return "<student>$rec</student>"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://928486]
help
Chatterbox?
[beech]: panick at the NN :)
[Discipulus]: which of 43 significance of NN?
[Discipulus]: NN?
[beech]: nobliest nodes
[Discipulus]: ah no newest nodes! ask something
[beech]: why is my butt itchy

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2016-12-09 09:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (150 votes). Check out past polls.