1

我的 XML 是:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <FindOrders xmlns="http://www.JOI.com/schemas/ViaSub.WMS/">
         <orders>
            <order>
               <MarkForName />
               <BatchOrderID />
               <CreationDate>2013-08-09T17:41:00</CreationDate>
               <EarliestShipDate />
               <ShipCancelDate />
               <PickupDate />
               <Carrier>USPS</Carrier>
               <BillingCode>Prepaid</BillingCode>
               <TotWeight>0.00</TotWeight>
               <TotCuFt>0.00</TotCuFt>
               <TotPackages>1.0000</TotPackages>
               <TotOrdQty>1.0000</TotOrdQty>
               <TotLines>1.00</TotLines>
               <Notes />
               <OverAllocated />
               <PickTicketPrintDate />
               <ProcessDate />
               <TrackingNumber />
               <LoadNumber />
               <BillOfLading />
               <MasterBillOfLading />
               <ASNSentDate />
               <ConfirmASNSentDate />
               <RememberRowInfo>398879:12:2:::0:False</RememberRowInfo>
            </order>
         </orders>
      </FindOrders>
      <totalOrders xmlns="http://www.JOI.com/schemas/ViaSub.WMS/">1</totalOrders>
   </soap:Body>
</soap:Envelope>

当我做:

$a = simplexml_load_string($str);

print_r($a);

我得到:SimpleXMLElement Object ( )而不是具有所有这些参数的对象。为什么是这样?

4

3 回答 3

1

您缺少SOAP的命名空间声明(php 手册)

$a = simplexml_load_string($str);
$a->registerXPathNamespace('soap', 'http://www.w3.org/2003/05/soap-envelope');

$result = $a->xpath('//soap:Body');

print_r($result);

结果(预览

Array
(
    [0] => SimpleXMLElement Object
        (
            [FindOrders] => SimpleXMLElement Object
                (
                    [orders] => SimpleXMLElement Object
                        (
                            [order] => SimpleXMLElement Object
  ...
  ...
于 2013-08-09T21:54:53.313 回答
0

我猜当您说要查看具有所有这些参数的对象时,您正在寻找输出刚刚创建的 xml 文档。

查看http://www.php.net/manual/en/simplexmlelement.asxml.php上的文档,您需要执行以下操作:

echo $a->asXML();
于 2013-08-09T21:55:37.420 回答
0

我的案子是处理肥皂反应。在将其转换为数组之前,我必须先对其进行解析和清理。

$response = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $xml); // remove all colons and unnecessary characters.
$xml = new SimpleXMLElement($response);
$body = $xml->xpath('//sBody'); // should refer to soap body element like soapbody, sbody, etc..
$array = json_decode(json_encode((array)$body), TRUE);
于 2022-02-22T05:59:48.597 回答