Right, I think, from piecing together the clues from all the other posts I have worked out what you want to do. You want to add a new <LIST /> with the next values of NICKID and ROWID so you need to find the greatest existing values. This then should do it:

use XML::XPath; my $file = 'memlist.xml'; my $xp = XML::XPath->new(filename=>$file); my $nodeset = $xp->find('/MEMBERLIST/LIST'); + my $max_nickid = -1; my $max_rowid = -1; + foreach my $list ( $nodeset->get_nodelist) { my $nickid = $list->findvalue('NICKID/text()')->value(); my $rowid = $list->findvalue('ROWID/text()')->value(); + $max_nickid = $nickid if ($nickid > $max_nickid); $max_rowid = $rowid if ($rowid > $max_rowid); } + print "NICK: $max_nickid ROWID: $max_rowid\n";

On a more general note I think you might be better served if you explain what it is you are trying to do in a wider sense in future as you seem to be posting lots of little questions dealing with a very small part of your larger problem which makes it difficult for people to help you, it also seems to indicate that you don't have a clear design of what you are trying to achieve when you start out, explaining the bigger picture to us will almost certainly help you get a view of what you are trying to achieve as well as making it possible for us to make suggestions as to how to achieve what you want rather than nibbling away at the problem.

/J\


In reply to Re^3: How to retrieve the last node value by gellyfish
in thread Retrieving the last node value from an XML file by antovinraj

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.