php getElementById

First, note that the function name is getElementById, not getElementByID, or getElementsById.

Second, this function is a member of DOMDocument, not DOMElement. If you get a DOMElement parent and try to get its child element using parent->getElementById(), you will get the following error:

Fatal error: Call to undefined method DOMElement::getElementById() in …

This is unlike Javascript or other programming languages in which dom element has its getElementById function.

 

Third, the function returns null if there is no doctype declaration in the parsed xml file even there is an element with that id in the xml file.

Fourth, if you don’t specify the doctype declaration in the xml file, you can write the id attribute  as xml:id=”attributevalue”. This way, getElementById  can return the element successfully. But loading the xml will trigger a warning message:

Warning: DOMDocument::load(): xml:id : attribute value xxx is not an NCName in file

Did you like this?
Tip admin with Cryptocurrency

Donate Bitcoin to admin

Scan to Donate Bitcoin to admin
Scan the QR code or copy the address below into your wallet to send some bitcoin:

Donate Bitcoin Cash to admin

Scan to Donate Bitcoin Cash to admin
Scan the QR code or copy the address below into your wallet to send bitcoin:

Donate Ethereum to admin

Scan to Donate Ethereum to admin
Scan the QR code or copy the address below into your wallet to send some Ether:

Donate Litecoin to admin

Scan to Donate Litecoin to admin
Scan the QR code or copy the address below into your wallet to send some Litecoin:

Donate Monero to admin

Scan to Donate Monero to admin
Scan the QR code or copy the address below into your wallet to send some Monero:

Donate ZCash to admin

Scan to Donate ZCash to admin
Scan the QR code or copy the address below into your wallet to send some ZCash:
Posted in

Comments are closed, but trackbacks and pingbacks are open.