Re: Why does simpleXML give me nested objects for blank tags?
| From: | Nathan Nobbe | Date: | Mon, 22 Jun 2009 20:22:07 +0000 |
| Subject: | Re: Why does simpleXML give me nested objects for blank tags? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-294418@lists.php.net to get a copy of this message | ||
On Mon, Jun 22, 2009 at 2:13 PM, Daevid Vincent <daevid@daevid.com> wrote:
> Repost as I got zero replies. Does anyone know why this is? Seems like a
> bug
> to me, or at least should be documented as such whacky behavior. Are there
> any solutions to this or work-arounds?
>
> -----Original Message-----
> From: Daevid Vincent [mailto:daevid@daevid.com]
> Sent: Thursday, June 18, 2009 6:04 PM
>
> I'm trying to use
> http://us2.php.net/manual/en/function.simplexml-load-string.php
>
> $xml_url =
>
> file_get_contents('http://myserver/cgi-bin/foo.cgi?request=c901c906e4d06a0
> ')
> ;
> try
> {
> $xml = simplexml_load_string($xml_url, 'SimpleXMLElement',
> LIBXML_NOBLANKS & LIBXML_COMPACT &
> LIBXML_NOEMPTYTAG);
> print_r( $xml);
> }
> catch (Exception $e)
> {
> echo "bad xml";
> }
>
> If I have this XML file (note the tags I marked with --> below):
>
> <issue>
> <crstatus>i_field_submitted</crstatus>
> <problem_number>151827</problem_number>
> <problem_synopsis_field>title</problem_synopsis_field>
> <problem_description_field>description2</problem_description_field>
> <fi_priority>High</fi_priority>
> --> <assignee/>
> <create_time>5/12/2009 22:53:10</create_time>
> --> <fi_notes_oem/>
> <fi_sw_part_name>sw_part_name</fi_sw_part_name>
> <fi_general_reference>general_reference</fi_general_reference>
> <fi_sw_part_number>sw_part_num</fi_sw_part_number>
> <fi_customer_ecd_date>1244703600</fi_customer_ecd_date>
> <fi_sw_part_version>sw_part_version</fi_sw_part_version>
> <fi_required_date>1243839600</fi_required_date>
> --> <ac_type/>
> </issue>
>
> Why does it give me sub-objects and not just empty strings for tags that
> have no values as I'd expect??!
first off, why does it matter.
second, i dont think its a bug, thats just how it works,
php > $a = simplexml_load_string('<blah/>');
php > var_dump($a);
object(SimpleXMLElement)#1 (0) {
}
> I tried all those options above and none of them make a difference.
>
> SimpleXMLElement Object
> (
> [crstatus] => i_field_submitted
> [problem_number] => 151827
> [problem_synopsis_field] => title
> [problem_description_field] => description2
> [fi_priority] => High
> --> [assignee] => SimpleXMLElement Object
> (
>
> )
>
> --> [fi_notes_oem] => SimpleXMLElement Object
> (
>
> )
>
> [fi_sw_part_name] => sw_part_name
> [fi_general_reference] => general_reference
> [fi_sw_part_number] => sw_part_num
> [fi_customer_ecd_date] => 1244703600
> [fi_sw_part_version] => sw_part_version
> [fi_required_date] => 1243839600
> --> [ac_type] => SimpleXMLElement Object
> (
>
> )
>
> )
third the documentation says var_dump() / print_r() are not supported, so i
wouldnt put much stock in the dump of the object above.
from the manual:
http://us2.php.net/manual/en/function.simplexml-element-attributes.php
"*Note*: SimpleXML has made a rule of adding iterative properties to most
methods. They cannot be viewed using
var_dump()<http://us2.php.net/manual/en/function.var-dump.php>or
anything else which can examine objects."
-nathan