Hello all,

I am trying to build a client to consume a webservice, and have run into some strange issues. Here is my code:

$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);
}

My problem is that the getElementByTagName never finds anything. This is the returned XML from the webservice:

<object>
    <success>true</success>
    <count>3</count>
    <assessments>
        <assessment>
            <assessmentid><![CDATA[201]]></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[695]]></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[708]]></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>

I'm quite the n00b when it comes to PHP, but as far as I can tell, this looks right (at least close). I'm sure I'm missing something blatently obvious though.

Thanks

Recommended Answers

All 6 Replies

This is the returned XML from the webservice

So the problem is in parsing the result?

I think, yes. Basically, I have no way of knowing if it is actually getting the results. I know the service returns them correctly (it's been tested in 3 other languages), so the disconnect must be somewhere in the parsing. If I use:

$soapURL = "http://test.prophecyhealth.com/ProphecyConnect/ProphecyConnectXML.cfc?method=GetAssessments&SecurityCode=A7D5B7D8-73E2-44D2-A6F8-4ACFB91843BF&AssessmentID=-1&AssessmentType=Test";
$assessmentList = file_get_contents($soapURL);
echo $assessmentList;

it will actually dump the correct return content. But I still cannot parse it this way. I have the same problem when get to the $xml->getElementsByTagName("assessment") part.

If you do print_r($assessmentList); what does it output? Add it after line 7 in the code of your OP.

I get call.stdClass Object ( [GetAssessmentsReturn] => true101 ) which looks right (the actual call returns 101 assessment records).

stdClass Object means it's an object, and not an XML string. Probably one of it's properties is. So you'll have to change this:

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

Fantastic! That worked perfectly.

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

Thank you!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.