FluentDOM icon indicating copy to clipboard operation
FluentDOM copied to clipboard

setAttributeNodeNS()

Open ThomasWeinert opened this issue 11 years ago • 0 comments

setAttributeNodeNS() actually behaves different from setAttributeNode(). Think about redefining the behavior or at least documenting it:

$dom = new DOMDocument();
$dom->formatOutput = TRUE;
$dom->appendChild($dom->createElement('element'));
$dom->documentElement->setAttributeNS('urn:foo', 'foo:attribute', 42);
$attribute = $dom->createAttributeNS('urn:bar', 'bar:attribute');
$attribute->value = 21;
$dom->documentElement->setAttributeNode($attribute);
echo $dom->saveXml();

$dom = new DOMDocument();
$dom->formatOutput = TRUE;
$dom->appendChild($dom->createElement('element'));
$dom->documentElement->setAttributeNS('urn:foo', 'foo:attribute', 42);
$attribute = $dom->createAttributeNS('urn:bar', 'bar:attribute');
$attribute->value = 21;
$dom->documentElement->setAttributeNodeNS($attribute);

echo $dom->saveXml();

Output

<?xml version="1.0"?>
<element xmlns:foo="urn:foo" xmlns:bar="urn:bar" bar:attribute="21"/>
<?xml version="1.0"?>
<element xmlns:foo="urn:foo" xmlns:bar="urn:bar" foo:attribute="42" bar:attribute="21"/>

ThomasWeinert avatar Sep 15 '14 14:09 ThomasWeinert