ruby - Searching a list of similar elements for a given value -
i have xml this:
<team ...some attributes...> <name>my team</name> <player uid="player1"> <name>name</name> <position>goalkeeper</position> <stat type="first_name">name</stat> <stat type="last_name">last</stat> <stat type="birth_date">bday</stat> <stat type="birth_place">bplace</stat> <stat type="weight">84</stat> <stat type="height">183</stat> <stat type="jersey_num">1</stat> </player> <player uid="player2"> ... </player> ... </team> i want search players jersey_num. i'm using nokogiri , code gets me sort of close:
feed.xpath("/team[@uid='#{team_uid}']//player/stat[@type='jersey_num']") that returns players in given team, , array of jersey number attribute rows, want find player given jersey number, , pull uid.
i can ancestor, first need search yield 1 matching player. realize @ moment i'm not searching it, i'm not sure how search given stat type syntax.
"... want find player given jersey number, , pull uid"
then xpath parameter should :
/team[@uid='#{team_uid}']//player[stat[@type='jersey_num' , .='#{jersey_num}']]/@uid or maybe without trailing /@uid player element, , further extraction ruby code. notice stat[....] part in above xpath filters stat element type attribute value , value of element itself.
Comments
Post a Comment