Okay, Got your point. I should write the contents into my xml file to see the changes. I tried this and gave me an error : can't call method "getEncoding" on an undefined value ...
MODIFIED CODE : 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"); } } } open(INFILE,">C:/perl/perl_tests/xmlin2.xml"); $doc->printToFile("C:/perl/perl_tests/xmlin2.xml"); $doc->dispose; close(INFILE);
In reply to Re^2: How to modify an XML file using XML::DOM
by ankit.tayal560
in thread How to modify an XML file using XML::DOM
by ankit.tayal560
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |