ankit.tayal560 has asked for the wisdom of the Perl Monks concerning the following question:
I've written this code but the modifications are not reflecting in the xml file.am I missing something important in the code? confused about using perl in xml! would be glad if someone can help and explain in a detailed manner how to perform this task? I am getting output as Joey 67890
use strict; use warnings; use Data::Dumper; use XML::DOM; my $parser=new XML::DOM::Parser; my $doc=$parser->parsefile('C:\perl\perl_tests\xmlin.xml') or die$!; my $root=$doc->getDocumentElement(); my @address=$root->getElementsByTagName("address"); foreach my $address(@address) { if($address->getAttribute("name") eq "tayal") { if($address->getAttribute("id")=='70889') { $address->setAttribute("name","Joey"); $address->setAttribute("id","67890"); my $temp1=$address->getAttribute("name"); my $temp2=$address->getAttribute("id"); print("$temp1\t$temp2\n\n"); } } } XML FILE : <config logdir="var/log/foo/" debugfile="tmp/foo.debug"> <server name ="sahara" osname ="solaris" osversion="2.6"> <address name="ankit" id="70888"/> <address name="tayal" id="70889"/> </server> <server name="gobi" osname="irix" osversion="6.5"> <address name="anshul" id="70689"/> </server> <server name="kalahari" osname="linus" osversion="2.0.34"> <address name="raghu" id="45678"/> <address name="lucky" id="67895"/> </server> </config>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to modify an XML file using XML::DOM
by afoken (Chancellor) on Sep 28, 2016 at 05:54 UTC | |
by ankit.tayal560 (Beadle) on Sep 28, 2016 at 06:23 UTC | |
by haukex (Archbishop) on Sep 28, 2016 at 06:50 UTC | |
by ankit.tayal560 (Beadle) on Sep 28, 2016 at 10:28 UTC | |
by ankit.tayal560 (Beadle) on Sep 28, 2016 at 08:12 UTC | |
|
Re: How to modify an XML file using XML::DOM
by choroba (Cardinal) on Sep 28, 2016 at 08:52 UTC | |
|
Re: How to modify an XML file using XML::DOM
by Laurent_R (Canon) on Sep 28, 2016 at 06:12 UTC | |
by ankit.tayal560 (Beadle) on Sep 28, 2016 at 06:27 UTC |