1

我正在尝试构建一个客户端来使用 Web 服务,但遇到了一些奇怪的问题。这是我的代码:

$securityCode = "A7D5B7D8-73E2-44D2-A6F8-4ACFB91843BF"; // The security code has been changed to an invalid code to prevent unwanted "visitors".
$ProphecyConnect = new SoapClient("http://test.prophecyhealth.com/ProphecyConnect/ProphecyConnectXML.cfc?wsdl");
try
{
    $params = array(SecurityCode => $securityCode, AssessmentID => -1, AssessmentType => "Test");
    $assessmentList = $ProphecyConnect->__soapCall("GetAssessments", array($params));
}
catch(Exception $exception)
{
    var_dump($exception);
}
$xml = new DOMDocument();
$xml->loadXML( $assessmentList );
try
{
    foreach($xml->getElementsByTagName("assessment") as $assessment)
    {
        foreach($assessment->childNodes as $node)
        {
            printf(
            "Name: %s - Type: %s - Value: %s\n",
            $node->nodeName,
            $node->nodeType,
            urlencode($node->nodeValue)     
            );
        }
    }
}
catch(Exception $ex)
{
    echo "Something happened.";
    var_dump($ex);
}

我的问题是 getElementByTagName 永远找不到任何东西。这是从 Web 服务返回的 XML:

<object>
    <success>true</success>
    <count>3</count>
    <assessments>
        <assessment>
            <assessmentid><![CDATA[123]]></assessmentid>
            <assessmentname><![CDATA[Cardiac Cath Lab V1]]></assessmentname>
            <assessmenttype><![CDATA[Test]]></assessmenttype>
            <costpoints><![CDATA[1]]></costpoints>
            <numberofquestions><![CDATA[23]]></numberofquestions>
            <timelimit><![CDATA[1380]]></timelimit>
        </assessment>
        <assessment>
            <assessmentid><![CDATA[456]]></assessmentid>
            <assessmentname><![CDATA[Cardiac Progressive Care Exam A V1]]></assessmentname>
            <assessmenttype><![CDATA[Test]]></assessmenttype>
            <costpoints><![CDATA[1]]></costpoints>
            <numberofquestions><![CDATA[75]]></numberofquestions>
            <timelimit><![CDATA[4500]]></timelimit>
        </assessment>
        <assessment>
            <assessmentid><![CDATA[789]]></assessmentid>
            <assessmentname><![CDATA[Cardiac Progressive Care Exam B V1]]></assessmentname>
            <assessmenttype><![CDATA[Test]]></assessmenttype>
            <costpoints><![CDATA[1]]></costpoints>
            <numberofquestions><![CDATA[75]]></numberofquestions>
            <timelimit><![CDATA[4500]]></timelimit>
        </assessment>
    </assessments>
</object>

在 PHP 方面,我是相当的 n00b,但据我所知,这看起来是正确的(至少接近)。我敢肯定我错过了一些明显的东西。

谢谢

4

1 回答 1

1

原来 SOAP 调用返回一个对象,而不是一个字符串。因此,当我将 $assessmentList 变量传递给 $xml.loadXML() 函数时,我实际上需要传递包含 xml 的属性。像这样:

$xml->loadXML($assessmentList->GetAssessmentsReturn);

这非常有效。

于 2013-09-11T17:49:23.050 回答