I am trying to replace one element of XML document with a new element using XML::Twig. The element value file does not change in the player.xml. I am new to this module

Here is the code snippet:

use strict; use warnings; use XML::Twig; use Data::Dumper; my $twig = XML::Twig->new(); $twig->parsefile( "player.xml"); # build the twig my $root= $twig->root; $root->set_tag( 'stats_test'); $root->print;

And the sample XML file(player.xml):

<stats> <player> <name>Houston, Allan</name> <g>69</g> <ppg>20.1</ppg> <rpg>3.4</rpg> <apg>2.8</apg> <blk>14</blk> </player> <player> <name>Sprewell, Latrell</name> <g>69</g> <ppg>19.2</ppg> <rpg>4.5</rpg> <apg>4.0</apg> <blk>15</blk> </player> <player> <name>Ewing, Patrick</name> <g>49</g> <ppg>14.6</ppg> <rpg>10.0</rpg> <apg>1.0</apg> <blk>68</blk> </player> <player> <name>Johnson, Larry</name> <g>57</g> <ppg>11.1</ppg> <rpg>5.3</rpg> <apg>2.6</apg> <blk>7</blk> </player> </stats>

Any help will be appreciated . Thanks ab


In reply to Not able to replace element value using XML::Twig by newbie_ab

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.