I have the following XML file loaded into php simplexml.
<adf>
<prospect>
<customer>
<name part="first">Bob</name>
<name part="last">Smith</name>
</customer>
</prospect>
</adf>
using
$customers = new SimpleXMLElement($xmlstring);
This will return “Bob” but how do I return the last name?
echo $customers->prospect[0]->customer->contact->name;
You can access the different
<name>elements by number, using array-style syntax.In fact, you’re already doing it for the
<prospect>element!See also Basic SimpleXML Usage in the manual.
If you want to select elements based on some criteria, then XPath is the tool to use.