Need to parse the XML and fetch specific tag's value
We need to display just the tags where correct words are placed - "sports" and "secure" which are appearing in tag <str name="word">WORD</str>
in below XML
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>
Currently, using ajax to fetch the data by calling ajax as mentioned here : In the ajax call :
$.ajax({
type: "GET",
url: solrurl,
dataType: "xml",
cache: false,
success: function(data) {
console.log(data);
},
error : function(data)
{
alert(Contact the Solr Admin);
}
});
Tried using response.spellcheck.suggestions[0], but its throwing error - tried by putting other parameters as well, but it didn't work!
Could anyone please suggest or advise on getting just the words sports and secure in an array.