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.