javascript - How can I find an XML element by one of its attributes, and retrieve the value of its other attribute? -


for example, have following in xml file:

<decisionpoint filename="5"> <choice label="arin, ripe, apnic" goto="5aa"/> <choice label="whois.org, network solutions" goto="5aa"/> <choice label="google, bing, yahoo" goto="5c"/> </decisionpoint> 

i have value filename=5, , have label value whois.org, network solutions, , need retrieve value of goto on <choice> has label value. how can go doing jquery?

do need make array of entire xml file? if so, after that? understand finding element name, i'm not sure direction go in far finding element x attribute, retrieving value of y attribute.

jquery lets issue queries search inside parsed xml fragment :

var xml = '<decisionpoint filename="5">\ <choice label="arin, ripe, apnic" goto="5aa"/>\ <choice label="whois.org, network solutions" goto="5aa"/>\ <choice label="google, bing, yahoo" goto="5c"/>\ </decisionpoint>'; var $xml = $(xml); 

then

var gt = $xml.find('choice[label="whois.org, network solutions"]').attr('goto'); 

to find element exact attribute value , retrieve value of goto.

or find part of attribute :

var gt = $xml.find('choice[label*="whois.org"]').attr('goto'); 

demonstration (open console)


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -