PHP使用XML Expat Parser

It seems odd to me that when I ran my simple code, Expat Parser runs through top to bottom of given XML string. If there is different element with same name, like below, how can I create different handlers and assign them?

<car>
    <name>
    ...
</car>
<person>
    <name>
    ...
</person>

If I want car>name element and person>name element parse other way, how can I find the current element's parent?