package Ledmonds::TSDCRUtils; use Ledmonds::DCRnode; sub new { my $class = shift; return bless {}, $class; } #---------------------------------------------------- # getNodeValue returns a nodes value #---------------------------------------------------- sub getNodeValue { my $className = shift; my ($NODE_REF, $nodeName) = @_; my $nodeValue; my $NO_DEBUG = 0; if (defined $NODE_REF->get_node($nodeName)) { my $thisNode = $NODE_REF->get_node($nodeName); $nodeValue = $thisNode->value(); } else { $nodeValue = ""; } return $nodeValue; } #---------------------------------------------------- # updateNodeValue updates a node if given the # node name and new value # returns 1 on success and 0 on failure #---------------------------------------------------- sub updateNodeValue { my $className = shift; my ($NODE_REF, $nodeName, $newValue) = @_; $ND = 1; my $bReturnCode = 0; if (defined $NODE_REF->get_node($nodeName)) { my $thisNode = $NODE_REF->get_node($nodeName); } else { print ("
---unable to get a node reference for $nodeName and value $oldValue, exiting ---
\n") unless ($ND); print (LOGFILE "
---unable to get a nodereference for $nodeName and value $oldValue, exiting ---
\n") unless ($ND); return; } my $thisValue = $thisNode->value() if (defined $thisNode); $thisNode->set_inner_xml($newValue) if (defined $thisNode); } #---------------------------------------------------- # replaceNodeValue updates a node if given the # node name, old value and new value #---------------------------------------------------- sub replaceNodeValue { my $className = shift; my ($NODE_REF, $nodeName, $oldValue, $newValue) = @_; $ND = 1; my $bReturnCode = 0; if (defined $NODE_REF->get_node($nodeName)) { my $thisNode = $NODE_REF->get_node($nodeName); } else { print ("
---unable to get a node reference for $nodeName and value $oldValue, exiting ---
\n") unless ($ND); print (LOGFILE "
---unable to get a nodereference for $nodeName and value $oldValue, exiting ---
\n") unless ($ND); return; } my $thisValue = $thisNode->value() if (defined $thisNode); #update by doing a match if ($oldValue eq $thisValue && length($oldValue >0) && length($thisValue >0)){ print ("
---replacing value based on condition---
\n") unless ($ND); print ("replace conditon is $thisValue equal $oldValue ---
\n") unless ($ND); my $bSetNode = $thisNode->set_inner_xml($newValue) if (defined $thisNode); print "found the node setting value of new node to $newValue.....
\n" unless ($ND); print ("Value of new node is $newValue
\n") unless ($ND); $foo = $thisNode->value(); print ("Verifying value of new node from XML - $foo
\n") unless ($ND); } } #---------------------------------------------------- # showAllNodes shows all nodes in an xml file #---------------------------------------------------- sub showAllNodes { my $className = shift; my($NODE_REF) = @_; #my $NO_DEBUG = %{$con}->{"NO_DEBUG"}; my @nodes = $NODE_REF->get_node_list('*'); foreach $node (@nodes) { print "node type: ", $node->type() , ".....", "node value: ", $node->value() , "\n"; } } 1;