Actually what should happen (I did not run the code) is that your program prints the modified element in books.xml for each title (from the element->print in the loop, then prints the entire books.xml resulting from the last loop, where indeed only 'Learning Perl on Win32 Systems' has been updated.

What are you trying to do exactly? The example seems really contrived.

In any case, your existing code processes books.xml and awfull lots of time (once per title)! If you really wanted to do this you should parse the first file, changing the titles and storing a hash old_title => new title (if memory is a problem you can use twig_roots / purge during the parse and tie the hash to a DBM file), then parse the second file, and replace each title found in the hash by the value (once again using twig_roots / purge if memory is tight).

Does this help?


In reply to Re: Problem in parsing XML file using XMl::Twig by mirod
in thread Problem in parsing XML file using XMl::Twig by ramya2005

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.