使用SOAP PHP创建XML消息

时间:2011-04-18 03:38:54

标签: php xml soap

嘿所有人。我正在尝试使用PHP SOAPClient创建类似的XML标记。我理解如何创建我需要的xml。但是,我需要创建具有相同标记名但属性不同的XML标记:

<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>

我目前使用foreach循环创建此行:

$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']);
}

1 个答案:

答案 0 :(得分:0)

您是否尝试过制作一系列费率?

$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']);
}