Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Finding max value from a unique tag from XML

by choroba (Canon)
on Nov 22, 2012 at 13:19 UTC ( #1005131=note: print w/ replies, xml ) Need Help??


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

A single XPath expression can find a maximum. Here is an example using XML::XSH2, a wrapper around XML::LibXML:

open 1.xml ; echo //doc/str[@name="docuid" and not(text() < //doc/str[@name="docuid +"]/text())] ;
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re: Finding max value from a unique tag from XML
Download Code
Replies are listed 'Best First'.
Re^2: Finding max value from a unique tag from XML
by tobyink (Abbot) on Nov 22, 2012 at 16:08 UTC

    That's more XPath wizardry than I'd normally manage. FWIW, here's the translation of the above to plain old XML::LibXML:

    use 5.010; use XML::LibXML 1.70; my $xml = XML::LibXML->load_xml(location => "1.xml"); say $xml->findnodes(q{ //doc/str[@name="docuid" and not(text() < //doc/str[@name="docuid" +]/text())] });
    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (13)
As of 2015-07-31 08:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (275 votes), past polls