ID:               42083
 Updated by:       [EMAIL PROTECTED]
 Reported By:      mail_ben_schmidt at yahoo dot com dot au
 Status:           Open
-Bug Type:         SimpleXML related
+Bug Type:         Documentation problem
 Operating System: Mac OS X
 PHP Version:      5.2CVS-2007-07-18
 New Comment:

Reclassified.


Previous Comments:
------------------------------------------------------------------------

[2007-08-18 01:36:02] mail_ben_schmidt at yahoo dot com dot au

>From the SimpleXML functions page in the manual (just prior to one of
the later examples):

"Data in SimpleXML doesn't have to be constant. The object allows for
manipulation of all of its elements."

I think setting attributes comfortably fits into 'all of its elements',
although 'elements' is probably a poor word to choose in this context.

My understanding is that SimpleXML is just meant to be consistent and
logical, so that it doesn't need lots of specific documentation. You can
manipulate its objects like you would expect to manipulate any other PHP
objects: unsetting deletes stuff, assigning changes stuff, or adds
stuff, enumerating goes through stuff. And it works for subelements,
attributes, whatever. If it's not allowed you get a warning or error,
not a silent failure or invalid XML document. That said, the extension
is not all that well documented yet, something I have volunteered to
help with a bit, and will do when I have some time (I must say, I was a
bit scared off by the length of the documentation about the
documentation...but I hope to get to it before too long).

Ben.

------------------------------------------------------------------------

[2007-08-17 20:04:54] [EMAIL PROTECTED]

Where is it documented that you're allowed to modify the xml document
like this? For me this just looks like abuse.

------------------------------------------------------------------------

[2007-07-24 04:03:11] mail_ben_schmidt at yahoo dot com dot au

Also forgot to explicitly mention that the same attribute can also be
added twice using array notation, thereby generating invalid XML.

------------------------------------------------------------------------

[2007-07-24 03:17:34] mail_ben_schmidt at yahoo dot com dot au

Description:
------------
OK! This one really is a bug! I know it must be a bug as invalid XML is
produced that can't be parsed! I have also tried it with
php5.2-200707181030, though just running the binary in sapi/cli/php
rather than doing make install.

When attributes are set or added using array notation, this is not done
according to the currently active scope of the SimpleXMLElement in use.

Deletion and access work as expected, however. Thus a newly
added/modified attribute cannot then be deleted or accessed without
changing namespaces to the unnamed namespace by use of attributes().

Reproduce code:
---------------
$str=<<<DONE
<?xml version="1.0" encoding="utf-8"?>
<root xmlns="http://localhost/a"; xmlns:ns="http://localhost/a";>
<elem attr="abc"/>
<elem ns:attr="abc"/>
<ns:elem attr="abc"/>
<ns:elem ns:attr="abc"/>
</root>
DONE;

$xml =
simplexml_load_string($str,'SimpleXMLElement',0,'http://localhost/a');
foreach ($xml->children('http://localhost/a') as $elem) {
        unset($elem['attr']);
        $elem['attr']="new";
        $elem['attr']="three";
        echo $elem['attr']."\n";
}
echo $xml->asXML();


Expected result:
----------------
three
three
three
three
<?xml version="1.0" encoding="utf-8"?>
<root xmlns="http://localhost/a"; xmlns:ns="http://localhost/a";>
<elem attr="abc" ns:attr="three"/>
<elem ns:attr="three"/>
<ns:elem attr="abc" ns:attr="three"/>
<ns:elem ns:attr="three"/>
</root>


Actual result:
--------------
[begins with four blank lines]




<?xml version="1.0" encoding="utf-8"?>
<root xmlns="http://localhost/a"; xmlns:ns="http://localhost/a";>
<elem attr="abc" attr="new" attr="three"/>
<elem attr="new" attr="three"/>
<ns:elem attr="abc" attr="new" attr="three"/>
<ns:elem attr="new" attr="three"/>
</root>



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=42083&edit=1

Reply via email to