简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM