PHP DOMElement是不变的。 ='无修改允许错误' [英] PHP DOMElement is Immutable. = 'No Modification Allowed Error'
问题描述
$ domEl = new DOMElement(Item);
$ domEl-> setAttribute('Something','bla');
抛出异常
code>>未捕获的异常DOMException,消息为无修改允许错误;
我以为我可以创建一个DOMElement,它将是可变的。
从 http://php.net/manual/en/domelement.construct.php
创建一个新的DOMElement对象。 此对象是只读。它可以附加到文档,但是在节点与文档关联之前,可能不会将附加节点附加到此节点。要创建可写节点,请使用
DOMDocument :: createElement
或DOMDocument :: createElementNS
。
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.
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
orDOMDocument::createElementNS
.
这篇关于PHP DOMElement是不变的。 ='无修改允许错误'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!