You are here: SimpleXML doesn't work with one single XML tag line... « PHP « IT news, forums, messages
SimpleXML doesn't work with one single XML tag line...

Posted by "Daevid Vincent" on 10/21/47 11:21

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:

root@DAEVID:/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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация