我正在尝试构建一个客户端来使用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永远找不到任何东西。这是来自webservice的返回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,但就我所知,这看起来是正确的(至少接近)。我确信我错过了一些明显的东西。
由于
答案 0 :(得分:1)
原来,SOAP调用返回一个对象而不是字符串。所以当我将$ assessmentList变量传递给$ xml.loadXML()函数时,我实际上需要传递包含xml的属性。像这样:
$xml->loadXML($assessmentList->GetAssessmentsReturn);
这很有效。