Soap signal cannot be parsed using SimpleXML

I use native soapclient () to call WSDL, but I cannot use simplexml to parse the result. I get an error message:

Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Extra content at the end of the document 

This doesn't seem to be a namespace problem, and I already tried the fix mentioned elsewhere on the site to remove the colons from the input string.

EDIT:

Thanks Gordon

Yes you are right. The server is a Microsoft site using data sets.

If I declare a client soap with a trace equal to true:

 $soapClient = new soapclient($this->wsdlUrl,array('trace'=>true)); 

and then extracting the raw XML from the response:

 $soapResult = $soapClient->GetScheduledSectors(); $responseXml = $soapClient->__getLastResponse(); $xml = simplexml_load_string($responseXml, NULL, NULL, "http://schemas.xmlsoap.org/soap/envelope/"); 

then I get:

 SimpleXMLElement Object ( [Body] => SimpleXMLElement Object ( ) ) 

The response XML header and the first tag are as follows:

 <?xml version='1.0'?> <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> <GetScheduledSectorsResponse xmlns="https://www.kulula.com/k3api/"> <GetScheduledSectorsResult msdata:SchemaSerializationMode="ExcludeSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xs:schema id="dsFlight" targetNamespace="http://tempuri.org/dsFlight.xsd" attributeFormDefault="qualified" elementFormDefault="qualified" xmlns:mstns="http://tempuri.org/dsFlight.xsd" xmlns="http://tempuri.org/dsFlight.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msprop="urn:schemas-microsoft-com:xml-msprop"> <xs:element name="dsFlight" msdata:IsDataSet="true" msdata:UseCurrentLocale="true" msprop:ExecutionTime="1140"> <xs:complexType> <xs:choice minOccurs="0" maxOccurs="unbounded"/> </xs:complexType> </xs:element> </xs:schema> <diffgr:diffgram xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"> <dsFlight xmlns="http://tempuri.org/dsFlight.xsd"> <FlightSector diffgr:id="FlightSector1" msdata:rowOrder="0"> <FlightSectorId>1</FlightSectorId> <FlightSectorName>JNBCPT</FlightSectorName> <FromAirport>OR Tambo (Jo'burg)</FromAirport> <ToAirport>Cape Town</ToAirport> <DepartureAirportId>1</DepartureAirportId> <ArrivalAirportId>2</ArrivalAirportId> <AirlineCode>BA</AirlineCode> <Ordernumber>100</Ordernumber> <FlightZoneId>1</FlightZoneId> <DepartureCountryCode>ZA</DepartureCountryCode> <DepartureContinentCode>AF</DepartureContinentCode> </FlightSector> 

I also tried registering the following namespaces:

 $xml = simplexml_load_string($this->responseXml, NULL, NULL, "http://schemas.xmlsoap.org/soap/envelope/"); $xml->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/'); $xml->registerXPathNamespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $xml->registerXPathNamespace('xsd', 'http://www.w3.org/2001/XMLSchema'); $xml->registerXPathNamespace('diffgr', 'urn:schemas-microsoft-com:xml-diffgram-v1'); $xml->registerXPathNamespace('mstns', 'http://tempuri.org/dsFlight.xsd'); $xml->registerXPathNamespace('msprop', 'urn:schemas-microsoft-com:xml-msprop'); 

but still get an empty object in $ xml

+4
source share
3 answers

You can try DOMDocument instead of simpleXML, as it seemed a bit more vulnerable in my past use. Not so fast though.

However, when I needed to parse SOAP, I returned to how to parse SOAP XML? and found some great info on the native PHP 5 Soap client.

+1
source

I have the same problem, then I try:

 $soapResult = $soapClient->GetScheduledSectors(); $responseXml = $soapClient->__getLastResponse(); $dom = new DomDocument(); $dom->loadXML($responseXml ); $phpObject = simplexml_load_string($dom->textContent); print_r($phpObject ); 

And see the results.

+1
source

I also run into this problem. After contacting the web service developer, I got a response that this answer is not XML, but DATATABLE (which is a C # type).

Finally, my solution was to create my own custom parser instead of using my own PHP modules.

Try using explode () according to the appropriate fields. I know this is not the best solution (definitely not the best practice). However, if you cannot get it in a different format, this may work for you.

0
source

Source: https://habr.com/ru/post/1396371/


All Articles