Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
P is for Practical
 
PerlMonks  

Re: Finding max value from a unique tag from XML

by remiah (Hermit)
on Nov 22, 2012 at 10:45 UTC ( #1005104=note: print w/ replies, xml ) Need Help??


in reply to Finding max value from a unique tag from XML

Hello Shaveta_Chawla.

It seems your xml have some trouble like '<\doc>'.
If it is valid xml, XML::Twig will do like this.

#!/usr/bin/perl use strict; use warnings; use XML::Twig; my $xml=join('', <DATA>); my $max_docid=0; XML::Twig->new( twig_roots =>{ 'str[@name="docuid"]' => \&set_max_docid, }, )->parse($xml); sub set_max_docid { my ($twig, $elt)= @_; my $docid= $elt->first_child_trimmed_text; if ($docid > $max_docid ){ $max_docid=$docid } } print "max docid=$max_docid\n"; __DATA__ <all> <doc> <date name="processingtime">2011-04-09T11:12:22.049Z</date> <str name="docuid">121422</str> <str name="title">ABC</str> </doc> <doc> <date name="processingtime">2012-04-09T11:12:22.049Z</date> <str name="docuid">13427</str> <str name="title">CDE</str> </doc> <doc> <date name="processingtime">2010-04-09T11:12:22.049Z</date> <str name="docuid">89822</str> <str name="title">LKK</str> </doc> </all>
XML::Twig has nice tutorial.


Comment on Re: Finding max value from a unique tag from XML
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1005104]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2014-04-20 11:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls