Saving an XML file from XPath (perl)

Posted on 2004-11-22
Last Modified: 2013-11-19
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...

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 ""){
# How do I save the XML file here?

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

Question by:pr0fess0r
    1 Comment
    LVL 2

    Accepted Solution

    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.


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


    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
    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…
    Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
    The viewer will learn how to count occurrences of each item in an array.

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now