Thread: XPath

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    2
    Rep Power
    0

    XPath


    Hi,

    I am writing a script that compares two xml documents and merges the changes into a third xml document. At the moment the script finds changes (for example: /company/employee[3]/). I am running into issue where XPath function (setNodeText($path, $text)
    doesnt seem to save to harddisk but rather to memory).

    Is there anyway to commit changes to harddisk using this approach?

    Thanks.
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,663
    Rep Power
    1958
    Please post your code related to you problem, in code tags.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    2
    Rep Power
    0
    Originally Posted by MrFujin
    Please post your code related to you problem, in code tags.
    Code:
    use XML::XPath;
    use XML::SemanticDiff;
    
    
    
    
    # create object
    
    my $diff = XML::SemanticDiff->new();
    
    # read XML file
    my $data1 ="xml1.xml";
    my $data2 ="xml2.xml";
    
    
    
    my $xpath = "";
    
      foreach my $change ($diff->compare($data1, $data2)) {
          #print "$change->{message} in context $change->{context}\n";
    	  
    	  $xpath = $change->{context};
    	  my $myDirCopyToUpdate = XML::XPath->new($data2);
    	  print $myDirCopyToUpdate->getNodeText($xpath);
    	  print "\nUpdate my copy: ", $myDirCopyToUpdate->setNodeText($xpath, "Test123") , "\n";
    		
    }

    these changes dont seem to commit.

IMN logo majestic logo threadwatch logo seochat tools logo