Link to home
Start Free TrialLog in
Avatar of pr0fess0r
pr0fess0r

asked on

Saving an XML file from XPath (perl)

Hi
Is it possible to save a modifed XMl file in Perl's XPath?
I have a script that looks for blank id attributes in an xml file and populates them with a unique ID...

[CODE]
my $updated=0;
my $xp = XML::XPath->new(filename => $file);
my $nodeset = $xp->find('//@id'); # find all ids
      foreach my $node ($nodeset->get_nodelist) {
                  my $id=$node->string_value;
                  if ($id eq ""){
                        $xp->setNodeText('@id',getUniqueId());
                                $updated=1;
                  }
      }
if($updated){
# How do I save the XML file here?
}
[/CODE]

Am I on the right track? How do I save the XML?
many thanks in advance!

Lucas
ASKER CERTIFIED SOLUTION
Avatar of exile_4
exile_4

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial