0

I'm trying to use simplexml_load_string like so:

$xml = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <data_GetResult xmlns="http://api.source.com/">
      <data_GetData>
        <value>123456</value>
        <value>789000</value>
      </data_GetData>
    </data_GetResult>
  </soap:Body>
</soap:Envelope>';      

$results = simplexml_load_string($xml);
print_r($results);

However, no results are returned, it simply shows:

SimpleXMLElement Object
(
)

I believe the xml is proper, I tested it in on-line validators. Thank you.

0

1 Answer 1

1

Try this (as per the manual)

<?php
$string = <<<XML
<?xml version="1.0" encoding="utf-8"?>
<soap_Envelope xmlns_xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns_xsd="http://www.w3.org/2001/XMLSchema" xmlns_soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap_Body>
<data_GetResult xmlns="http://api.source.com/">
<data_GetData>
<value>123456</value>
<value>789000</value>
</data_GetData>
</data_GetResult>
</soap_Body>
</soap_Envelope>  
XML;

$xml = simplexml_load_string($string);

print_r($xml);
?>

It seems as though the : in your names were (which is odd they seem part of the scheme) causing the problem e.g.

</soap:Body>
</soap:Envelope>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. Replace the : with _ did work. Weird as it is part of the scheme and I have had no problems with similarly constructed APIs.

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.