For your question about quote and not quote the variable, I have adjust the code into the same direction as following:<?xml version="1.0" encoding="UTF-8"?> <company name="ABC" branch="bangkok"> <employee code="emp0001"> <info> <general> <name>Somchai Chaisom</name> <photo>/employee/photo/emp001.gif</photo> <position>Helpdesk Officer</position> <department>IT</department> </general> </info> <education> <record> <institute>Mahidol</institute> <year>2548-2550</year> <degree>Master</degree> <faculty>IT</faculty> <major>IT</major> <gpa>2.6</gpa> </record> </education> </employee> <employee code="emp0002"> <info> <general> <name>Manee Meena</name> <photo>/employee/photo/emp002.gif</photo> <position>Programmer</position> <department>IT</department> </general> </info> <education> <record> <institute>Siam University</institute> <year>2538-2542</year> <degree>Bachelor</degree> <faculty>Engineer</faculty> <major>Software Engineering</major> <gpa>3.3</gpa> </record> <record><institute>test</institute><degree>test</degree><g +pa>test</gpa><faculty>test</faculty><major>test</major><year>test</ye +ar></record> </education> </employee> </company>
For your comment about:#!/usr/bin/perl use warnings; use XML::DOM; $link = "Thammasat"; %rlinks = ( "institute" => "test", "year" => "test", "degree" => "test", "faculty" => "test", "major" => "test", "gpa" => "test", ); my $rfile = "employee.xml"; my $xparser = XML::DOM::Parser->new(); my $xdoc = $xparser->parsefile($rfile); $ritem = $xdoc->createElement("record"); foreach $key (keys %rlinks) { $new = $xdoc->createElement($key); $text = $xdoc->createTextNode($rlinks{$key}); $new->appendChild($text); $ritem->appendChild($new); } foreach my $xitem ($xdoc->getElementsByTagName("record")) { $durl = $xitem->getElementsByTagName("institute")->item(0)->getFir +stChild->getNodeValue; if($durl eq $link) { $p = $xitem->getParentNode(); $p->replaceChild($ritem,$xitem); #this return incorrect resu +lt #$xdoc->getDocumentElement()->replaceChild($ritem,$xitem); #t +his return NOT_FOUND_ERR } } $xdoc->printToFile($rfile);
It returns error after I change to: error = Can't locate object method "getNodeValue" via package "XML::DOM::NodeList"$xitem->getElementsByTagName('institute')->item(0)->getFirstChild->get +NodeValue;
$xitem->getElementsByTagName('institute')->getNodeValue;
In reply to Re^2: XML::DOM - NOT_FOUND_ERR
by sureerat
in thread XML::DOM - NOT_FOUND_ERR
by sureerat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |