I want to convert a DOMNode
object from a call to getElementsByTagName()
to a DOMElement
in order to access methods like getElements
You don't need to do any explicit typecasting, just check if your DOMNode object has a nodeType of XML_ELEMENT_NODE
.
PHP will be perfectly happy with this.
If you use PHPLint to check your code you will notice that PHPLint complains about using getElementsByTagName
on a DOMNode object. To get around this you need to jump through the following hoop:
/*.object.*/ $obj = $node;
$element = /*.(DOMElement).*/ $obj;
Then you will have a $element variable of the correct type and no complaints from PHPLint.