[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Updating with perl XML::LibXML

  • To: <xml-dev@l...>
  • Subject: Updating with perl XML::LibXML
  • From: "Cameron" <ccrum@d...>
  • Date: Wed, 14 Jun 2006 09:02:20 -0500

perl xml libxml
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.