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"); $address->setAttribute("flags","4"); my $temp1=$address->getAttribute("name"); my $temp2=$address->getAttribute("id"); my $temp3=$address->getAttribute("flags"); print("$temp1\n\n"); print("$temp2\n\n"); print("$temp3\n\n"); my $temp_item=$root->createElement("item"); my $temp_data=$root->createElement("data"); my $child1=$address->appendChild($temp_item); $child1->setAttribute("used","1"); $child1->setAttribute("order","0"); my $g=$child1->getAttribute("used"); my $h=$child1->getAttribute("order"); print("$g\t$h\n"); my $child2=$child1->appendChild($temp_data); $child2->setAttribute("typeid","4"); my $k=$child2->getAttribute("typeid"); print("$k\n"); } } } $doc->setXMLDecl($doc->createXMLDecl('1.0','UTF-8')); $doc->printToFile("C:/perl/perl_tests/xmlin2.xml"); $doc->dispose; XML FILE :