Мыло в XML преобразование в PHP
Вопрос
Мне нужно генерировать следующий XML с мылом:
...
<InternationalShippingServiceOption>
<ShippingService>StandardInternational</ShippingService>
<ShippingServiceCost currencyID="USD">39.99</ShippingServiceCost>
<ShippingServicePriority>1</ShippingServicePriority>
<ShipToLocation>CA</ShipToLocation>
</InternationalShippingServiceOption>
...
Итак, у меня есть следующий мыльный массив в PHP, чтобы сделать это:
$params = array(
'InternationalShippingServiceOption' => array(
'ShippingService'=>'StandardInternational',
'ShippingServiceCost'=>39.99,
'ShippingServicePriority'=>1,
'ShipToLocation'=>'CA',
)
)
$client = new eBaySOAP($session); //eBaySOAP extends SoapClient
$results = $client->AddItem($params);
Все отлично работает, кроме как я не генерирую currentyId = "USD" Атрибут в теге ShippingServiceCost в XML. Как мне это сделать?
Решение
Вам не нужно использовать Soapvar. Это работает (по крайней мере для меня):
$params = array(
'InternationalShippingServiceOption' => array(
'ShippingService'=>'StandardInternational',
'ShippingServiceCost' => array('_' => 39.99, 'currencyID' => 'USD')
'ShippingServicePriority'=>1,
'ShipToLocation'=>'CA',
)
)
Я использую эту технику с API PayPal SOAP.
Другие советы
Почему, я рад, что ты спросил. Я только что решил это сегодня.
$shippingsvccostwithid = new SoapVar(array('currencyID' => $whatever),SOAP_ENC_OBJECT, 'ShippingServiceCost', 'https://your.namespace.here.com/');
$params = array("InternationalShippingServiceOption" => array(
"ShippingService" => "StandardInternational",
"ShippingServiceCost" => $shippingsvccostwithid,
"ShippingServicePriority" => 1,
"ShipToLocation" => "CA"
);
А затем продолжать как нормально.
Пожалуйста, дайте мне знать, если вам нужна дополнительная помощь.
Не связан с StackOverflow