Reputation: 1114
I want to parse this code to get the values
Currently I do
$(user).find('x item').each(function () {
var first = $(this).context.getElementsByTagName('value')[3].childNodes[0]['textContent'];
});
just to get "Sam" from Sam
I am sure there is a better and more reliable way do the same. I also want to find a way to avoid this kind of errors if any of the values are missing:
TypeError: $(...).context.getElementsByTagName(...)[2].childNodes[0] is undefined
Upvotes: 0
Views: 51
Reputation: 388316
Since you are getting the exception I'm guessing the $(user).find('x item')
selector is fine. So you can try
$(user).find('x item').each(function () {
var first = $(this).find('field[var="first"] value').text();
});
Upvotes: 3