CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Update an XML node value based on one of the attribute values.

 



amitp2011
New User

Apr 17, 2014, 10:39 PM

Post #1 of 2 (8888 views)
Update an XML node value based on one of the attribute values. Can't Post

I have to update the value of a node by based on the value of one of its attributes.

<ReferenceID referenceIDType="FXDD">FXDDILN233</ReferenceID>
For the above Tag.
i want to edit the value FXDDILN233 based on the attribute value referenceIDType="FXDD"

I tried the below code:

Code
my $nodeset = $doc->findnodes("//*[name()='ReferenceID']"); 
foreach my $node ($nodeset->get_nodelist) {
if ($node->hasAttribute("referenceIDType") == XML::LibXML::Boolean->True) {
$RetVal = $node->getAttributeNode("referenceIDType")->getValue();
if ($RetVal eq "FXDD") {
print "Attribute VAL=@@@@@@@@@@@@"."$RetVal \n";
$node->setData("$NodeVal");
}

}
}

Code
But getting error on the setData line.. 
Whats is it that could be wrong ?
Thanks in advance.


(This post was edited by amitp2011 on Apr 17, 2014, 11:18 PM)


amitp2011
New User

Apr 21, 2014, 4:36 AM

Post #2 of 2 (8306 views)
Re: [amitp2011] Update an XML node value based on one of the attribute values. [In reply to] Can't Post

I found the solution.

Code
my $nodeset = $doc->findnodes("//*[name()='ReferenceID']");  
foreach my $node ($nodeset->get_nodelist) {
if ($node->hasAttribute("referenceIDType") == XML::LibXML::Boolean->True) {
$RetVal = $node->getAttributeNode("referenceIDType")->getValue();
if ($RetVal eq "FXDD") {
print "Attribute VAL=@@@@@@@@@@@@"."$RetVal \n";
$node->firstChild->setData("blah blah"); [\b]
}

}
}



(This post was edited by amitp2011 on Apr 21, 2014, 4:37 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives