I have this ugly XML which has alot of namespaces on it, when I try to load it with simpleXML if i indicate the first namespace I\'d get an xml object ,but following tags with o
The rate data can be accessed like this:
Demo
$obj = simplexml_load_string($xml);
foreach($obj->children('http://schemas.xmlsoap.org/soap/envelope/')->Body->children('urn:wsTest')->ServiceNameRQ->GetRatesRS->Rates->Rate as $rate)
{
echo (string)$rate->RateName . "\n";
}
Outputs
Rack Rate
Normal Rate
If you want the Rate attributes, you can get them like this (within the loop):
echo $rate->attributes()->RateID;
You can read the R1
and R2
elements like this:
foreach($obj->children('http://schemas.xmlsoap.org/soap/envelope/')->Body->children('urn:wsTest')->ServiceNameRQ->GetRatesRS->Rates->Rate as $rate)
{
if(isset($rate->R1))
{
echo $rate->R1->attributes()->Name;
echo $rate->R1->attributes()->MinRate;
}
if(isset($rate->R2))
{
echo $rate->R2->attributes()->Name;
echo $rate->R2->attributes()->MinRate;
}
}