Maybe I'm missing something about XML specifications, but this doesn't seem
right to me.

http://www.php.net/manual/en/ref.simplexml.php

Here is a code fragment I use:

$xml = simplexml_load_string($returnData);
var_dump($xml);
if (is_object($xml))
{
        //first lets make sure we didn't get an <ERROR>
        if ($xml->error)
        {
                echo "An ERROR was encountered\n";
                echo "CODE: ".((string)$xml->error->code)."\n";
                echo "STRING: ".((string)$xml->error->string)."\n";
                exit;
        }

        ...
}

I have my XML setup such that if there is an error, I return:

        <?xml version="1.0" encoding="iso-8859-1" ?>
        <error code="tbd" string="user not found." />

But simple XML will not detect this as illustrated by var_dump($xml)

        object(SimpleXMLElement)#1 (0) {
        }

However, if I change my output to be:

        <?xml version="1.0" encoding="iso-8859-1" ?>
        <error>
          <code>tbd</code>
          <string>user not found with those credentials.</string>
        </error>

Then I get...

        object(SimpleXMLElement)#1 (2) {
          ["code"]=>
          string(3) "tbd"
          ["string"]=>
          string(38) "user not found."
        }

Notice also that my object is not nested inside an ["error"] as I would
expect it to be.
So I would expect to get this (in BOTH cases actually):

object(SimpleXMLElement)#1 (1) {
  ["error"]=>
        object(SimpleXMLElement)#1 (2) {
          ["code"]=>
          string(3) "tbd"
          ["string"]=>
          string(38) "user not found."
        }
}

More useful information:

[EMAIL PROTECTED]:/lockdown/includes/api# php -v
PHP 5.0.3 (cli) (built: Jul 11 2005 12:33:48)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.3, Copyright (c) 1998-2004 Zend Technologies
    with Zend Extension Manager v1.0.6, Copyright (c) 2003-2004, by Zend
Technologies
    with Zend Optimizer v2.5.7, Copyright (c) 1998-2004, by Zend
Technologies

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to