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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|