PHP简单解析SOAP响应

时间:2014-06-24 23:26:29

标签: php xml soap

我花了几个小时查看有关simpleXML等的所有帖子。

我想要的只是提取/设置值的简单方法。

示例:如何提取"地址"的值在“"数据"以下SOAP响应: (注意:我用[]代替尖括号)

    [?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]
    [FetchResponse xmlns="http://xxxxxx.com/WS/xxxx"]
    [WSResponse Code="1"]
    [Message]Fetched empty Email[/Message]
    [Data][?xml version="1.0" encoding="utf-16"?][Email xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Editor="0" Updated="1800-01-01T00:00:00" ID="0" ParentID="0" Address="" EmailType="Unknown" /]
    [/Data]
    [/WSResponse]
    [/FetchResponse]
    [/soap:Body]
    [/soap:Envelope]

RGDS 彼得拉什

2 个答案:

答案 0 :(得分:1)

请发布所有代码。

试试这个:

..
// Call wsdl function 
    $result = $client->__soapCall("YOURCALL", array()), NULL, $header); 

    print_r( $result->Email['Address'] )
    //Or
    print_r( $result->Data->Email['Address'] )

答案 1 :(得分:0)

感谢您的回复。然而...

使用:

// Call WSDL function 
$result = $APIClient->__soapCall("Fetch", array( 
    "Fetch" => array( 
        "id"        => $PersonID,
        "entity"    => "Email",
        "Alias"     =>  ""
    ) 
), NULL, $Header); 

第一个建议给出:

Notice: Undefined property: stdClass::$Email

第二个建议给出:

Notice: Undefined property: stdClass::$Data
$ p结果上的

print_r给出:

stdClass Object ( [WSResponse] => stdClass Object ( [Message] => Email record successfully located for ID: 11450. [Data] => [Code] => 1 ) ) 

RGDS 彼得拉什