Creating XML messages with SOAP PHP
Hey all. I am trying to create similar XML tags with PHP SOAPClient. I understand how to create the xml i need. However, it has come to a point where I need to create XML tags that have the same tag names but different attributes:
<Rates>
<Rate EffectiveDate="2011-12-15"> <Total AmountAfterTax="155" /> </Rate>
<Rate EffectiveDate="2011-12-16"> <Total AmountAfterTax="155" /> </Rate>
<Rate EffectiveDate="2011-12-17"> <Total AmountAfterTax="155" /> </Rate>
</Rates>
I currently use a foreach loop to create this line:
$request->Reservation['Rates'] = "";
foreach($Array['Rates'] as $Value)
{
$request->Reservation['Rates']['Rate']
= array("EffectiveDate" => $value['Date']);
$request->Reservation['Rates']['开发者_如何学运维Rate']['Total']
= array("AmountAfterTax" => $value['Price']);
}
Have you tried making an array of rates, like so?
$request->Reservation['Rates'] = "";
$Length = count($Array['Rates']);
for ($i = 0; $i < $Length; $i++)
{
$request->Reservation['Rates'][$i]['Rate']
= array("EffectiveDate" => $Array['Rates']['Date']);
$request->Reservation['Rates'][$i]['Rate']['Total']
= array("AmountAfterTax" => $Array['Rates']['Price']);
}
精彩评论