2017-02-08 12 views
2

私は解析しようとしているSOAP応答を持っていますが、エラーが発生しているようです。SOAP応答の解析PHP

SOAP応答:

Trying to get property of non-object

Iはまた、次のコードを試みた:

$doc = new DOMDocument(); 
$doc->loadXML($strXml); 
echo $doc->getElementsByTagName('Status')->item(0)->nodeValue; 

これは、次のエラーが生成さ:

私は、次のコードを試みた

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
<s:Body> 
<ValidateNewUserResponse xmlns="urn:websitea.com/v2"><ValidateNewUserResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Message i:nil="true"/> 
<Status>true</Status> 
<FailureReason>None</FailureReason> 
<IdentityValidationOutcome>0</IdentityValidationOutcome> 
<ValidationIdentifier>112244</ValidationIdentifier> 
</ValidateNewUserResult></ValidateNewUserResponse> 
</s:Body> 
</s:Envelope> 

次のエラー生成3210

simplexml_load_string(): namespace error : Namespace prefix i for nil on Message is not defined

+0

可能な複製(http://stackoverflow.com/questions/26467445/domdocument-simple-getelementsbytagname:あなたのコードは、次の(一重引用符を使用して)私のために働いたのテスト-wont-work) –

答えて

0

は、以下のことを試してみてくださいは、私のために正常に動作します。

$doc = new DOMDocument(); 
$doc->loadXML($strResponse); 
$result = $doc->getElementsByTagName('Status')->item(0)->nodeValue; 
echo $result; 
-1

それとも、あなたは常にPHPオブジェクトを処理しますとXMLレスポンスを解析したり、XML要求を生成する必要はありませんので、あなたは、PHPのジェネレータにWSDLを使用することができます。これは、基本的なネイティブPHP SoapClientクラスを使用する場合です。それはXML文字列が破損しているか適切にエスケープして、二重引用符を使用されていない場合は、エラーになりますビュー

0

の私のポイントにSOAPを消費するための最良の方法ですので、あなたはまた、PackageGeneratorとしてPHP発生器にWSDLを使用することができます。 [文句を言わない仕事のDOMDocumentシンプルgetElementsByTagNameの?]の

$strXml = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
<s:Body> 
<ValidateNewUserResponse xmlns="urn:websitea.com/v2"><ValidateNewUserResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Message i:nil="true"/> 
<Status>true</Status> 
<FailureReason>None</FailureReason> 
<IdentityValidationOutcome>0</IdentityValidationOutcome> 
<ValidationIdentifier>112244</ValidationIdentifier> 
</ValidateNewUserResult></ValidateNewUserResponse> 
</s:Body> 
</s:Envelope>'; 

$doc = new DOMDocument(); 
$doc->loadXML($strXml); 
echo $doc->getElementsByTagName('Status')->item(0)->nodeValue;