in reply to Not able to replace element value using XML::Twig

Your script seems to work fine. When I ran it, the substitution took place.

I don't know if there is a difference between $root->print and $twig->print, example code in the docs uses the latter but it didn't have any effect on my test runs. If you still have problems, you might use $twig just to be sure (even though I doubt it has something to do with it)

Replies are listed 'Best First'.
Re^2: Not able to replace element value using XML::Twig
by newbie_ab (Novice) on Jan 25, 2010 at 13:52 UTC

    Thanks , the file player.xml should be replaced with the change but it is not. I am able to see the change using $twig->print. Hope that makes sense.

      Ahh, that's the problem. You have to tell Twig explicitely to save it to a file (after all, a Twig user might not want to change the xml but just parse it, or print it to the screen).
      When I add
      $twig->print_to_file("player.xml");

      at the end of your script instead of the "$root->print;" line, the file on disk gets updated too


        Thanks , I did try with print_to_file but my code gives an error that cannot locate the function for object.
        Also even though I am creating an object of type XML::Twig but the object is being created of type XML::Twig::Elt which is a subclass of XML::Twig.
        That's another reason the function is not being located by the created object