How do I use jQuery to return a record from an XML file where the node name is duplicated?

111 Views Asked by At

How do I go about getting just one of the records from the XML file below using jQuery. The node name is duplicated in the XML data file:

    <category label="Certainty" scheme="masas:category:certainty" term="Observed" />
    <category label="Category" scheme="masas:category:category" term="Transport" />
    <category label="Severity" scheme="masas:category:severity" term="Minor" />
    <category label="Status" scheme="masas:category:status" term="Actual" />
    <category label="Icon" scheme="masas:category:icon" term="ems/incident/roadway/roadwayClosure" />strong text

This is the code I am currently using to retrieve text from the XML file:

icon = $(this).find("[nodeName='category']").text();

2

There are 2 best solutions below

0
On BEST ANSWER

Try this:

icon = $(this).find("[nodeName='category']").filter("[label='icon']").attr('term');
0
On
$('category[label=Icon]', this).attr('term')