Is there a way to append a DOMElement
directly with another DOMElement
without going through a DOMDocument
. I'm trying to make a navigation menu that can be used my another class that houses the DOMDocument
.
$navItem= new \DOMElement('li');
$domElement = new \DOMElement('ul');
$domElement->appendChild($navItem);
The DOMElement
class does extend the DOMNode
class so it does inherit all of the public methods from DOMNode
. So in the example above it should be capable of appending the $navItem
to the $domElement
.
Instead it returns
Uncaught exception 'DOMException' with message 'No Modification Allowed Error' in /redacted/navigation.php:15
Please help me.
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
.
Hope this helps you
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.