Problem with child nodes having same element name as parent
I'm trying to go through a collection of objects and read out a value 'location' for each, however, I don't want to pull out any values for each object's children that also may happen to be called 'location'. Using 'find' brings all the 'location' values right down the tree, whereas I just want the location values for the current level.
e.g.
<building>
<office>
<location>1st floor</location>
<person>
<location>office 10</location>
</person>
<person>
<location>3rd cubicle from left</location>
</person>
</office>
<office>
<location>2nd floor</location>
<person>
<location>office 16b</location>
</person
</office>
<building>
How do I just get the location of the offices (and not the people)? I'm trying as below, but this stores the location of the people objects too.
$xml.find('building').each(function(){
$(this).find('office').each(function(){
$myOfficeLocations += $(this).find('location').text();
});
});
Any ideas on how to do this?