I have an XML file which has four
tag:
You have a couple of options:
var xml = $(xml);
$('resultGroups > name', xml).each(function() {
alert($(this).text());
});
This uses the direct descendant selector. You could also use children, which does the same thing:
$('resultGroups', xml).children('name').each(function() {
alert($(this).text());
});