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

 ID:               51641
 Updated by:       m...@php.net
 Reported by:      jpatokal at iki dot fi
 Summary:          Adding namespace with addAttribute() adds spurious
                   xmlns:xmlns attribute
-Status:           Open
+Status:           Wont fix
 Type:             Bug
 Package:          SimpleXML related
 Operating System: All
 PHP Version:      5.2.13

 New Comment:

As its name implies SimpleXML is for simple access to XML, use a more
sophisticated interface like DOM.


Previous Comments:
------------------------------------------------------------------------
[2010-04-23 02:06:09] jpatokal at iki dot fi

Description:
------------
If you add a new namespace to a document root with addAttribute(), the
function incorrectly also tries to add a namespace for the new
namespace, resulting in a spurious "xmlns:xmlns" attribute.



Add attribute called "foo:bar"

xmlns:foo="namespace-url" foo:bar="value" <-- correct



Add attribute called "xmlns:bar"

xmlns:xmlns="namespace-url" xmlns:bar="namespace-url" <-- incorrect



A special case is thus needed to ensure that, if the attribute name
starts with "xmlns:", a namespace is not added for it:

xmlns:bar="namespace-url" <-- correct



Alternatively, a new function for adding namespaces to a document?



Test script:
---------------
<?php

$xml = new SimpleXMLElement('<office:document-content
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"/>');

$xml->addAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer',
'http://openoffice.org/2004/writer');

echo $xml->asXML();

?>





Expected result:
----------------
<?xml version="1.0"?>

<office:document-content
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
xmlns:ooow="http://openoffice.org/2004/writer"/>



Actual result:
--------------
<?xml version="1.0"?>

<office:document-content
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
xmlns:xmlns="http://openoffice.org/2004/writer";
xmlns:ooow="http://openoffice.org/2004/writer"/>




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



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

Reply via email to