2010-01-02 20 views
0

XML轉換我需要生成以下XML與SOAP:SOAP在PHP

    ... 
       <InternationalShippingServiceOption> 
         <ShippingService>StandardInternational</ShippingService> 
         <ShippingServiceCost currencyID="USD">39.99</ShippingServiceCost> 
         <ShippingServicePriority>1</ShippingServicePriority> 
         <ShipToLocation>CA</ShipToLocation> 
        </InternationalShippingServiceOption> 
        ... 

所以我在PHP以下SOAP數組做到這一點:

$params = array(
     'InternationalShippingServiceOption' => array(
      'ShippingService'=>'StandardInternational', 
      'ShippingServiceCost'=>39.99, 
      'ShippingServicePriority'=>1, 
      'ShipToLocation'=>'CA', 
     ) 
    ) 
$client = new eBaySOAP($session); //eBaySOAP extends SoapClient 
$results = $client->AddItem($params); 

一切都很正常,除非我不在XML中的ShippingServiceCost標記中生成currencyID =「USD」屬性。我該怎麼做呢?

+0

是不是想直,增加更多信息 – Jonah 2010-01-02 19:53:32

回答

0

您不需要使用SoapVar。這個工程(至少對我來說):

$params = array(
     'InternationalShippingServiceOption' => array(
      'ShippingService'=>'StandardInternational', 
      'ShippingServiceCost' => array('_' => 39.99, 'currencyID' => 'USD') 
      'ShippingServicePriority'=>1, 
      'ShipToLocation'=>'CA', 
     ) 
    ) 

我在PayPal SOAP API中使用了這種技術。

+0

如果你不介意,我有一個關於PayPal SOAP API的問題。你如何設置'版本'?當我設置它時,標記變爲'xsd:string'而不是'Version'。更多信息在這裏http://stackoverflow.com/questions/3105577/simple-php-soapclient-example-for-paypal-needed 謝謝! – Jonah 2010-06-24 18:19:40

0

爲什麼,我很高興你問。我今天就解決了這個問題。

$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" 
); 

然後繼續照常。

如果您需要任何幫助,請讓我知道。