I have a weird XML file that I’m trying to parse.
<Data>
<Row>
<Field name = "whatever" pos ="1">STUFF</Field>
<Field name = "whatever2" pos ="2">MORE STUFF</Field>
<Field name = "whatever3" pos ="3">EVEN MORE STUFF</Field>
</Row>
<Row>
<Field name = "whatever" pos ="1">Different STUFF</Field>
<Field name = "whatever2" pos ="2">MORE Different STUFF</Field>
<Field name = "whatever3" pos ="3">EVEN MORE Different STUFF</Field>
</Row>
</Data>
I tried getting the data by using “Row” which works but how do I call the individual field names? In firebug they all look like “Field”. I tried:
myvalue : $("whatever", this).text()
But that doesn’t grab it.
Thanks
Code from a comment below:
function callAjax(url) {
$.ajax({
url: url,
dataType: "xml",
success: function (xmlResponse) {
$.merge(data1, $("ROW", xmlResponse).map(returnResults).get());
} // end of success }); }
function returnResults() {
formatedURL = $('Field[name="EL_VALUES_FIELD2"]', this).text();
return {
value: $('Field[name="EL_VALUES_FIELD1"]', this).text(),
label: $('Field[name="EL_VALUES_FIELD1"]', this).text() + " " + $("EL_VALUES_FIELD4", this).text(),
title: $('Field[name="EL_VALUES_FIELD1"]', this).text(),
url: formatedURL,
description: $('Field[name="EL_VALUES_FIELD3"]', this).text(),
keywords: $('Field[name="EL_VALUES_FIELD4"]', this).text()
};
}
You can do this with the attribute equals selector
[attrname="value"]. For instance:This finds the
Fieldelement whose name iswhatever2within the first (index0)Rowelement.