Extracting specific values from XML tags
We are looking to extract and display only the tags that contain the words "sports" and "secure" within the
tag in the following XML:<str name="word">WORD</str>
XML
<response>
<lst name = "responseHeader">
<int name status>0</int>
<int name QTime>3</int>
</lst>
<result name="response",numFound="0",start="0"/>
<lst name="spellcheck">
<lst name="suggestions">
<lst name="sporsts">
<int name="numFound">1</int>
<int name="startOffset">0</int>
<int name="endOffset">5</int>
<int name="origFreq">0</int>
<arr name="suggestion">
<lst>
<str name="word">sports</str>
<int name="freq">1</int>
</lst>
</arr>
</lst>
<lst name="secuer">
<int name="numFound">1</int>
<int name="startOffset">6</int>
<int name="endOffset">17</int>
<int name="origFreq">0</int>
<arr name="suggestion">
<lst>
<str name="word">secure</str>
<int name="freq">1</int>
</lst>
</arr>
</lst>
</lst>
<bool name="correctlySpelled">false</bool>
</lst>
</response>
We are currently using AJAX to retrieve this data. The AJAX call is as follows:
$.ajax({
type: "GET",
url: solrurl,
dataType: "xml",
cache: false,
success: function(data) {
console.log(data);
},
error : function(data)
{
alert(Contact the Solr Admin);
}
});
We attempted to access the data using response.spellcheck.suggestions[0], but encountered errors. We tried different parameters without success!
Any suggestions on how we can specifically extract and store the words "sports" and "secure" into an array would be greatly appreciated.