2012-02-14 5 views
4

나는 WSDL을 호출하는 기본 soapclient()를 사용하고 사용한 구문 분석 할 수없는하지만 결과를 구문 분석하는 SimpleXML을 사용할 수 없습니다. 나는 지속적으로 오류 얻을 :비누 응답은 SimpleXML을

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

이 네임 스페이스 문제처럼 보이지 않는를하고 난 이미 입력 문자열에서 콜론을 제거하기 위해 사이트에 다른 곳에서 언급 된 패치를 시도했다.

편집 :

감사, 고든

네 말이 맞아. 서버는 데이터 세트를 사용하는 Microsoft 사이트입니다.

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

을 한 후 응답에서 원시 XML 검색 : 내가 참으로 추적 세트 비누 클라이언트를 선언하면

다음

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

를 내가 얻을 :

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

응답 XML 헤더와 첫 번째 태그는 다음과 같습니다.

<?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>O.R. 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> 
나는 또한 다음과 같은 네임 스페이스를 등록하는 것을 시도했다

:

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

을 여전히 $ XML의 빈 개체를 얻을

+1

루트 요소가없는 것 같습니다. – Gordon

답변

1
이 좀 더 오류를 보였다 것처럼

대신 SimpleXML을의있는 DOMDocument를 시도 할 수 있습니다 내 과거 사용법에 tolerent. 거의 빠르지는 않습니다. 내가 SOAP를 구문 분석하는 데 필요한 때

그러나, 나는 How to parse SOAP XML?에 refferred와 PHP 5 천연 비누 클라이언트에서 우수한 정보를 발견했다.

$soapResult = $soapClient->GetScheduledSectors(); 
$responseXml = $soapClient->__getLastResponse(); 

$dom = new DomDocument(); 
$dom->loadXML($responseXml); 

$phpObject = simplexml_load_string($dom->textContent); 
print_r($phpObject); 

을 그리고 결과를 볼 : 나는 같은 문제가

1

, 그럼 내가하려고합니다.

0

또한이 문제가 발생합니다. 웹 서비스 개발자에게 문의 한 후에이 응답은 XML이 아니라 데이터 형 (C# 데이터 형식)이라는 대답을 얻었습니다.

마지막으로 내 솔루션 대신 네이티브 PHP의 사람을 사용하는 내 자신의 파서를 만드는 것이 었습니다.

관련 필드에 따라 explode()를 사용해보십시오. 이것이 최선의 해결책이 아님을 알고 있습니다. (모범 사례는 아닙니다.) 그러나 다른 형식으로 가져올 수없는 경우이 방법이 효과적 일 수 있습니다.