How to set name and value for a DOMNode in PHP?

333 Views Asked by At

The class DOMNode has attributes nodeName and nodeValue, but doesn't provide any setters for them. OK, nodeValue is public and can be accessed directly. But how to set the readonly nodeName?

1

There are 1 best solutions below

5
On

Don't create a DOMNode directly. Use a DOMElement. When you create a DOMElement (either directly, or through DOMDocument.CreateElement), you can specify a name.