3

我需要从返回 XML 格式数据的 .NET Web 服务访问响应。如何拆分返回的数据?例如,我想将数据解析为一些 PHP 变量:

$name = "Dupont";
$email = "charles.dupont@societe.com";

我一直在寻找如何做到这一点,但没有找到正确的方法。

我的脚本是:

$result = $client->StudentGetInformation($params_4)->StudentGetInformationResult;

    echo "<p><pre>" . print_r($result, true) . "</pre></p>";

我页面中的回声是:

stdClass Object
(
    [any] => 0Successful10371DupontCharlescharles.dupont@societe.com1234charles.dupont@societe.comfalsefr-FR1003FIRST FINANCE1778AAA Département
)

网络服务响应格式为:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <StudentGetInformationResponse xmlns="http://tempuri.org/">
      <StudentGetInformationResult>xml</StudentGetInformationResult>
    </StudentGetInformationResponse>
  </soap:Body>
</soap:Envelope>

我试过你的例子。但它不能满足我的需要。我需要拆分返回的值。我想获取数据并将它们放入 PHP 变量中:

$name = "杜邦"; $email = "charles.dupont@societe.com"; ETC...

不幸的是,您的示例的回声给出了:

object(stdClass)#1 (1) { ["StudentGetInformationResult"]=> object(stdClass)#11 (1) { ["any"]=> string(561) "0Successful10371DupontCharlescharles.dupont@societe.com1234charles.dupont@societe.comfalsefr-FR1003FIRST FINANCE1778AAA Département" } } 
4

1 回答 1

1

您唯一需要的课程是SoapClient. 您可以在PHP 文档中使用很多示例。

例子:

try {
    $client = new SoapClient ( "some.aspx?wsdl" );
    $result = $client->StudentGetInformation ( $params_4 );

    $xml = simplexml_load_string($result->StudentGetInformationResult->any);
    echo "<pre>" ;

    foreach ($xml as $key => $value)
    {
        foreach($value as $ekey => $eValue)
        {
            print($ekey . " = " . $eValue . PHP_EOL);
        }
    }

} catch ( SoapFault $fault ) {
    trigger_error ( "SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR );
}

输出

Code = 0
Message = Successful
stud_id = 10373
lname = Dupont
fname = Charles
loginid = charles.dupont@societe.com
password = 1234
email = charles.dupont@societe.com
extid = 
fdisable = false
culture = fr-FR
comp_id = 1003
comp_name = FIRST FINANCE
dept_id = 1778
dept_name = Certification CMF (Test web service)
udtf1 = 
udtf2 = 
udtf3 = 
udtf4 = 
udtf5 = 
udtf6 = 
udtf7 = 
udtf8 = 
udtf9 = 
udtf10 = 
Audiences = 
于 2012-04-06T13:41:49.237 回答