views:

234

answers:

3
$response = sendRequest($curl, doCreateDB($domainid, $dbname, $dbtype));             

$responseXml = parseResponse($response);


function parseResponse($response_string)
{
 $xml = new SimpleXMLElement($response_string);
 if (!is_a($xml, 'SimpleXMLElement'))
  throw new ApiRequestException("Cannot parse server response: {$response_string}");
 return $xml;
}

full output

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [version] => 1.5.0.0
        )

    [database] => SimpleXMLElement Object
        (
            [add-db] => SimpleXMLElement Object
                (
                    [result] => SimpleXMLElement Object
                        (
                            [status] => error
                            [errcode] => 1007
                            [errtext] => Database with requested name already exists
                        )

                )

        )

)

Final output at above. Then I want to get specific node's value. Eg: i want to get status node.

I tried a few ways, but can't seems to print out the specific data.

echo $responseXml->database->{add-db}->result->status; // (nothing come out)

etc...

A: 

Did you try ["database"] instead of ->database and so on?

EricSchaefer
A: 

Try

echo (string)$responseXml->database->{add-db}->result->status;
Anti Veeranna
not working. When I print the whole code, output without any problem. When only need to print value in specific node, nothing come out.
i need help
+1  A: 

Try this:

echo $responseXml->database->{'add-db'}->result->status;

Note the single quotes to select a hyphenated array item: {'...'}.

Mr. Smith
thank you for your syntax. It works perfectly after adding quote to the hypernated array.
i need help