[英]php DOMElement appendchild
Is there a way to append a DOMElement
directly with another DOMElement
without going through a DOMDocument
. 有没有办法直接将
DOMElement
与另一个DOMElement
附加,而无需通过DOMDocument
。 I'm trying to make a navigation menu that can be used my another class that houses the DOMDocument
. 我正在尝试创建一个导航菜单,可以使用我的另一个包含
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
. 在
DOMElement
类则扩展DOMNode
类,所以它继承了所有的公众方法DOMNode
。 So in the example above it should be capable of appending the $navItem
to the $domElement
. 因此在上面的示例中,它应该能够将
$navItem
附加到$domElement
。
Instead it returns 相反,它返回
Uncaught exception 'DOMException' with message 'No Modification Allowed Error' in /redacted/navigation.php:15
/redacted/navigation.php:15中未捕获的异常'DOMException',消息'No Modification Allowed Error'
Please help me. 请帮我。
From http://php.net/manual/en/domelement.construct.php 来自http://php.net/manual/en/domelement.construct.php
Creates a new DOMElement object. 创建一个新的DOMElement对象。 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
. 要创建可写节点,请使用
DOMDocument::createElement
或DOMDocument::createElementNS
。
Hope this helps you 希望这对你有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.