Hello i am trying to parse xml i have couple of trouble do this.
I am not able to get nested level element.For eg.telephone I am not able to get attribute value.I am not able to get and the third level nested element properly, i tried many code for that also for attribute values of some elements. like here telephone type and commercialListingType
Here is my xml
<propertyList date="2014-06-02-17:30:33" username="bad" password="dfdfd">
<business modTime="2014-06-02-12:22:32" status="current">
<agentID>TEST</agentID>
<uniqueID>1420648</uniqueID>
<listingAgent id="1">
<name>hjon Smith</name>
<telephone type="BH"></telephone>
<telephone type="mobile"></telephone>
<email>[email protected]</email>
</listingAgent><listingAgent id="2"></listingAgent>
<address display="no">
<subNumber>Yoghurt bbd 4000</subNumber>
<streetNumber></streetNumber>
<street></street>
<suburb display="no">Newy</suburb>
<state>NSW</state>
<postcode>2000</postcode>
<country>London</country>
</address>
<price display="yes" plusSAV="no" tax="exclusive">200000</price>
<priceView></priceView>
<externalLink href=""/><externalLink href=""/>
<videoLink href=""/>
<underOffer value="no"/>
<commercialListingType value="sale"/>
<franchise value="yes"/>
<businessCategory id="1">
<name>Franchise</name>
</businessCategory>
</propertyList>
Here is my code
<?php
$xml=simplexml_load_file("testing.xml");
$data = array();
foreach($xml->business as $business) {
$business = (array) $business;
if (!array_key_exists($business['uniqueID'], $data)) {
$listingAgent = (array) $business['listingAgent'];
$price = (array) $business['price'];
$commercialListingType= (array)$business['commercialListingType'];
print_r($commercialListingType->attributes());
$data[$business['uniqueID']] = array(
'agentID' => $business['agentID'],
'uniqueID' => $business['uniqueID'],
'name' => (string)$listingAgent[0]->name,
'email' => (string) $listingAgent[0]->email,
'price'=>(string) $price[0],
'telephone' => (string) $listingAgent[0]->telephone[0],
'mobile' => (string) $listingAgent[0]->telephone[1],
);
}
}
echo "<pre>";
print_r($data);
?>