note 125175 added to domdocument.getelementbyid
| From: | Hoi@php.net | Date: | Tue, 07 Jul 2020 22:39:54 +0000 |
| Subject: | note 125175 added to domdocument.getelementbyid | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-214845@lists.php.net to get a copy of this message | ||
To set a hidden id that can be used by $dom->getElementById() apply setAttribute('id',
true) as in the following example
$createItemNode = function ($data) use ($dom) {
$node = $dom->createElement("Item");
$node->setAttribute('id', $data->id);
$node->setAttribute('hed', $data->hed);
$node->setAttribute('run_time', $data->run_time);
$node->setAttribute('date', $data->date);
// Internally mark the id as 'xml:id' for getElementById to work.
Adding xml:id manually to the tag will cause loadXML to throw an error DOMDocument: xml:id is not a
NCName in Entity
$node->setIdAttribute('id', true);
return $node;
};
With $node->setIdAttribute('id', true), $dom->getElementById($id) will work
When you do $dom->saveXML(), the final doc will not contain any xml:id attribute.
----
Server IP: 45.112.84.4
Probable Submitter: 103.51.166.36 (proxied: 148.75.17.47)
----
Manual Page -- http://php.net/manual/en/domdocument.getelementbyid.php
Edit -- https://master.php.net/note/edit/125175
Del: integrated -- https://master.php.net/note/delete/125175/integrated
Del: useless -- https://master.php.net/note/delete/125175/useless
Del: bad code -- https://master.php.net/note/delete/125175/bad+code
Del: spam -- https://master.php.net/note/delete/125175/spam
Del: non-english -- https://master.php.net/note/delete/125175/non-english
Del: in docs -- https://master.php.net/note/delete/125175/in+docs
Del: other reasons-- https://master.php.net/note/delete/125175
Reject -- https://master.php.net/note/reject/125175
Search -- https://master.php.net/manage/user-notes.php