1

My XML is:

<?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>

When I do:

$a = simplexml_load_string($str);

print_r($a);

I get: SimpleXMLElement Object ( ) instead of an object with all of those parameters. Why is this?

0

3 Answers 3

2

You are missing the namespace declaration (php manual) for SOAP

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

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

print_r($result);

Result (preview)

Array
(
    [0] => SimpleXMLElement Object
        (
            [FindOrders] => SimpleXMLElement Object
                (
                    [orders] => SimpleXMLElement Object
                        (
                            [order] => SimpleXMLElement Object
  ...
  ...
Sign up to request clarification or add additional context in comments.

Comments

0

I'm guessing when you say you want to see an object with all those parameters, you're looking to output the xml document you just created.

Looking at the documentation at http://www.php.net/manual/en/simplexmlelement.asxml.php, here's what you need to do:

echo $a->asXML();

Comments

0

My case was dealing with soap response. I have to parse and clean it first before converting it to array.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.