【问题标题】:SOAP to XML conversion in PHPPHP 中 SOAP 到 XML 的转换
【发布时间】:2010-12-31 17:48:58
【问题描述】:

我需要使用 SOAP 生成以下 XML:

                    ...
                <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" 属性。我该怎么做?

【问题讨论】:

  • 想不通,添加了更多信息

标签: php xml soap ebay-api


【解决方案1】:

为什么,我很高兴你问。我今天刚刚解决了这个问题。

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

然后照常继续。

如果您需要更多帮助,请告诉我。

【讨论】:

    【解决方案2】:

    您不需要使用 SoapVar。这有效(至少对我来说):

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

    我正在将此技术与 PayPal SOAP API 一起使用。

    【讨论】:

    • 如果您不介意,我有一个关于 PayPal SOAP api 的问题。你如何设置“版本”?当我设置它时,标签变为'xsd:string'而不是'Version'。更多信息在这里stackoverflow.com/questions/3105577/…谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-24
    • 2011-08-25
    • 2017-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多