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

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.

  • Comment on Re^2: Not able to replace element value using XML::Twig

Replies are listed 'Best First'.
Re^3: Not able to replace element value using XML::Twig
by jethro (Monsignor) on Jan 25, 2010 at 14:12 UTC
    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

        my $twig = XML::Twig->new(); print ref $twig,"\n"; $twig->parsefile("player.xml"); my $root= $twig->root; print ref $root,"\n"; # prints: XML::Twig XML::Twig::Elt

        It seems you are still using $root for the method call instead of $twig. If I use $root->print_to_file instead of $twig->print_to_file, I too get the error message that the function can't be found