OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Updating with perl XML::LibXML

[ Lists Home | Date Index | Thread Index ]

I have a piece of code that I am writing in Perl using the XML::LibXML module. I seem to be able to extract all the information I want, but when trying to alter information in the file, for some reason it does not save. After altering the information, I can go back and view it again and it contains the altered information, but when I try to write it to a file, only the old information is there. Here is the piece of code:
 
use XML::LibXML;
$parser = new XML::LibXML ;
$file = "10001.xml";
open(outfile, ">10001n.xml");
$tree = $parser -> parse_file($file);
$root = $tree -> getDocumentElement();
 
foreach my $routers($root->findnodes('Routers')){
 foreach my $router($routers->findnodes('Router')){
  $rtr_name = $router->findvalue('Name');
  print $rtr_name, "\n";
  foreach my $APS($router->findnodes('APs')){
   foreach my $AP($APS->findnodes('AP')){
    $ap_name = $AP->findvalue('Name');
    print "   " . $ap_name . "\n";
    foreach my $customers($AP->findnodes('Customers')){
     foreach my $cust($customers->findnodes('Customer')){
      $cust_name = $cust->findvalue('First')." ".$cust->findvalue('Last');
      $lst_ping = $cust->findvalue('Last_Ping');
      print "     " . $cust_name . " " . $lst_ping ."\n";
      
 
      #get node for altering last_ping data
      foreach $lst_ping_node($cust->findnodes('Last_Ping')){
       $lst_ping_txt=XML::LibXML::Text->new( $lst_ping_node -> textContent );
       print $lst_ping_txt->data . "\n";
       $cur_ping = '15';
       $lst_ping_txt->setData( $cur_ping );
       print $lst_ping_txt->data ."\n";
       }
 
      }
     }
 

    }
   }
 

 }
}
 

$outstr=$tree->toString;
print outfile $outstr;
 
The print statesments are just to show that I am extracting the correct information. What I want to do is update the <Last_Ping> element in my XML file. If I add another loop to go through and grab the data again after making the changes and print out the text form the node, the new values are there, but they don't show up in the output file. Can anyone see anthing wrong with my logic here?
 
Regards,
 
Cameron




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS