Mantis - Quercus
Viewing Issue Advanced Details
6004 minor always 05-15-16 08:38 07-03-16 13:07
ebo  
nam  
normal  
closed  
not fixable  
none    
none  
0006004: SimpleXML reorders attributes
When adding attributes with SimpleXML, the attributes get reordered in alphabetic order. This causes issues when comparing XML documents.

The following code snippet:

$xml=simplexml_load_string('<?xml version="1.0" encoding="utf-8"?><test/>');
$child=$xml->addChild('foo', 'bar');
$child->addAttribute('xyz', 'first');
$child->addAttribute('abc', 'second');
echo '
' . htmlentities($xml->asXML()) . '
';

Outputs:

<?xml version="1.0"?>
<test><foo abc="second" xyz="first">bar</foo></test>

Notes
(0006709)
nam   
07-03-16 13:07   
According to the W3C DOM specs, attribute ordering is not guaranteed. It would be nice to match PHP, but it is not possible because Java's Xerces XML implementation does not support attribute ordering.