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',get UniqueId() );
$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
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',get
$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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.