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...
Am I on the right track? How do I save the XML?
many thanks in advance!
Lucas
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?
}
Am I on the right track? How do I save the XML?
many thanks in advance!
Lucas