2

I am getting XML response from third party service,

$soap = new SoapClient($wsdl, $options);
$data = $soap->method($params);

Response looks like Stdclass object values

$data contains the xml inside the array object

$data->resultResponse->any contains below xml format,

<xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet"><xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Temp" ..... </xs:element></xs:schema><diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"><DocumentElement xmlns=""><Temp diffgr:id="Temp1" msdata:rowOrder="0"><name>Siva</name><age>18</age>....<location>chennai</chennai></Temp><Temp diffgr:id="Temp2" msdata:rowOrder="0"><name>John</name><age>18</age>....<location>chennai</chennai></Temp>

I am getting below error When this xml using in to SimpleXMLElement or simplexml_load_string for array conversion ,

$res = $data->resultResponse->any;
$res1 = new SimpleXMLElement($res);
$res2 = simplexml_load_string($res);

For the both $res1 & $res2,

Warning: simplexml_load_string(): Entity: line 1: parser error : Extra content at the end of the document in soap.php on line 40

I don't want the "<xs:schema" from that xml. I want "<diffgr:diffgram" values.

Previously, I used nusoap library for this. That is working fine for less memory data. Nusoap converts the whole xml into array. But, Php-Soap client gives only the first-level elements as objects/key.

I tried already some ways in loadXml in DOM and preg_replace. But those are not much helpfull

Please help me to resolve the problem.

Original xml response getting from Boomerang,

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<ClaimMISResponse xmlns="http://tempuri.org/">
<ClaimMISResult>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Temp" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Temp">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" minOccurs="0" />
...
<xs:element name="location" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<DocumentElement xmlns="">
<Temp diffgr:id="Temp1" msdata:rowOrder="0">
<name>John</name>
...
<location>Chennai</location>
</Temp>
</DocumentElement>
</diffgr:diffgram>
</ClaimMISResult>
</ClaimMISResponse>
</soap:Body>
</soap:Envelope>
6
  • Possible duplicate of Parsing complex XML in PHP5 Commented Nov 18, 2016 at 14:30
  • @RahulSingh In my question the problem is Not getting response from simplexml_load_string. Commented Nov 18, 2016 at 14:50
  • The "XML" you posted, is incomplete and broken. Additionally it looks like two XMLs combined, an XML document can only have a single root element node. Otherwise it is an XML fragment. DOM can load XML fragments with DOMDocumentFragment::appendXml(). Commented Nov 18, 2016 at 15:47
  • @ThW Thanks. That xml was not the original from response. I have updated now in question. Please check it. Commented Nov 18, 2016 at 15:59
  • what is code on your soap.php Commented Nov 20, 2016 at 8:19

1 Answer 1

1

It's so easy, explode your result by </xs:schema>

$result = \explode('</xs:schema>', $data->resultResponse->any);
$array = json_decode(json_encode((array)simplexml_load_string($result[1])),true);
Sign up to request clarification or add additional context in comments.

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.