Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Saving an XML file from XPath (perl)

Posted on 2004-11-22
1
Medium Priority
?
595 Views
Last Modified: 2013-11-19
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
0
Comment
Question by:pr0fess0r
1 Comment
 
LVL 2

Accepted Solution

by:
exile_4 earned 2000 total points
ID: 12661469
Hi Lucas,

If you want to modify an XML I think the best way to go is PerlSAX, your code allows you only to query your XML and returned a nodeset of element that have an id attribute and its nestling elements.

Cheers,
Exile

---------------------------------------------------------------------------------------------------
The future belongs to those who believe in the beauty of their dreams......

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question