Skip to content
Advertisement

PHP DOMElement is Immutable. = ‘No Modification Allowed Error’

I cannot understand why this fails. Does a DOMElement need to be part of a Document?

$domEl = new DOMElement("Item"); 
$domEl->setAttribute('Something','bla'); 

Throws exception

> Uncaught exception 'DOMException' with message 'No Modification Allowed Error';

I would have thought I could just create a DOMElement and it would be mutable.

Advertisement

Answer

From http://php.net/manual/en/domelement.construct.php

Creates a new DOMElement object. This object is read only. It may be appended to a document, but additional nodes may not be appended to this node until the node is associated with a document. To create a writeable node, use DOMDocument::createElement or DOMDocument::createElementNS.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement