Try this:
var employees = $(xmfile).find("employee[id=20]");
if(employees.length == 1) {
var employee = employees[0];
var name = $(employee).find("name").text();
alert(name);
}
else if (employees.length == 0) {
alert("No employees found with that ID.");
}
else {
alert("Too many employees found with that ID.");
}
How it works: it finds all employees with 20 as ID and stores them in an array. If the length of that array is one, it stores the only item in the variable
employee
, looks for the element
name
, and stores the inner text in the variable
name
.