Shaveta_Chawla has asked for the wisdom of the Perl Monks concerning the following question:
I have an XML file,
where a tag (<str name="docuid">) appears multiple times. i need to fetch data from all the docid tags and find max value from that. I used following code::<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> <date name="processingtime">2010-04-09T11:12:22.049Z</date> <str name="docuid">89822</str> <str name="title">LKK</str> <\doc>
This code is solving my purpose, but is there any better way to achieve this.$html =~ s/<doc>/<doc>\n\n\n\n\n\n/g; my (@lines) = split("\n\n\n\n\n", $html); $cn = scalar(@lines); for($i = 0; $i<$cn; $i++) { if ($lines[$i] =~ m/<str name="docuid">(.*?)<\/str>/) { $docuid[$i] = $1; } } my $max = max @docuid;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Finding max value from a unique tag from XML
by remiah (Hermit) on Nov 22, 2012 at 10:45 UTC | |
Re: Finding max value from a unique tag from XML
by choroba (Cardinal) on Nov 22, 2012 at 13:19 UTC | |
by tobyink (Canon) on Nov 22, 2012 at 16:08 UTC | |
Re: Finding max value from a unique tag from XML
by jethro (Monsignor) on Nov 22, 2012 at 10:41 UTC | |
Re: Finding max value from a unique tag from XML
by vagabonding electron (Curate) on Nov 24, 2012 at 16:35 UTC | |
by Jenda (Abbot) on Nov 25, 2012 at 03:46 UTC | |
by vagabonding electron (Curate) on Nov 26, 2012 at 18:36 UTC | |
by afoken (Chancellor) on Nov 26, 2012 at 19:32 UTC | |
by vagabonding electron (Curate) on Nov 29, 2012 at 16:37 UTC |
Back to
Seekers of Perl Wisdom