I’ve got a DOMNode object that has some attributes. $Node->attributes is a DOMNamedNodeMap, which has no methods for removing one of the entries in the map. The DOMNode class also has no methods for removing attributes from an element. I’ve looked through a number of the other related classes and none of them seem to provide a mechanism for removing an attribute node from its parent.
DOMNode::removeChild doesn’t work; it throws a ‘Not found error’ if I pass a DOMAttr object to it.
Aside from constructing a new DOMNamedNodeMap and adding all the attributes to it except the one I don’t want… any ideas? Thanks.
If you’ve got a
DOMNodethat has some attributes, it must be aDOMElement. In which case you should be able to callremoveAttribute/removeAttributeNS/removeAttributeNodeon it.It is somewhat curious that PHP’s
DOMNamedNodeMapdocumentsgetNamedItem[NS]but does not acknowledge the existencesetNamedItem[NS]andremoveNamedItem[NS], which would have been another way of doing it.DOMNode::removeChildcan’t work because aDOMAttris not a child of anotherDOMNode; ‘attributes’is a separate space tochildNodes. You also can’t create a newNamedNodeMapon its own to write toDOMNode::attributes, as that’s a read-only property.