Bug #61597 [Opn->Fbk]: SimpleXML drops attributes for tags with both attributes and text
| From: | aharvey@php.net | Date: | Mon, 02 Apr 2012 06:41:26 +0000 |
| Subject: | Bug #61597 [Opn->Fbk]: SimpleXML drops attributes for tags with both attributes and text | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-169126@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=61597&edit=1
ID: 61597
Updated by: aharvey@php.net
Reported by: drgroove at gmail dot com
Summary: SimpleXML drops attributes for tags with both
attributes and text
-Status: Open
+Status: Feedback
Type: Bug
Package: SimpleXML related
Operating System: Mac OS X
PHP Version: 5.3.10
Block user comment: N
Private report: N
New Comment:
I can't reproduce this:
<?php
$xml = <<<'EOX'
<?xml version="1.0"?>
<parent>
<child attr="foo">text content</child>
</parent>
EOX;
$doc = simplexml_load_string($xml);
printf("Text content: %s; attribute: %s\n", $doc->child,
$doc->child['attr']);
?>
Outputs "Text content: text content; attribute: foo", as I'd expect. Are you
able to provide a reproduction script?
The SO discussion appears to be about JSON encoding only; given that
SimpleXMLElement doesn't support serialisation, I'd suggest that the same would
apply to JSON encoding.
Previous Comments:
------------------------------------------------------------------------
[2012-04-02 03:37:26] drgroove at gmail dot com
Description:
------------
When loading XML into SimpleXML, tags which have both attributes and text will have their attributes
dropped.
For example, loading this into SimpleXML:
<sometag attribute="value">Here is some text</sometag>
Will cause 'attribute="value"' to be lost. If there is no text w/in a tag, but
attributes, the attributes and their values are preserved.
I'm not the only PHP developer to notice this bug; please see:
http://stackoverflow.com/questions/8563073/disappearing-attributes-in-php-simplexml-object
I didn't see this bug reported on php.net, however.
Test script:
---------------
See above.
Expected result:
----------------
Tags with both attributes and text should not have their attributes dropped.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=61597&edit=1