Search code examples
jqueryxmlgeorss

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


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();


Solution

  • Try this:

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