|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-04-16 20:04 UTC] s dot li at gmx dot de
The following script returns bool(false):
<?php
$src = <<< _END
<html>
<head><title> Test </title></head>
<body>
<h1>Test</h1>
<span id="test">Foo</span>
</body>
</html>
_END;
$doc = domxml_open_mem($src);
$n = $doc->get_element_by_id("test");
var_dump($n);
?>
Workaround: Use Xpath expressions to find the node:
<?php
$src = <<< _END
<html>
<head><title> Test </title></head>
<body>
<h1>Test</h1>
<span id="test">Foo</span>
</body>
</html>
_END;
$doc = domxml_open_mem($src);
$ctx = $doc->xpath_new_context();
$res = $ctx->xpath_eval("//*[@id='test']");
$n = $res->nodeset[0];
var_dump($n);
?>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Thu Feb 05 06:00:01 2026 UTC |
Quote from the Document Object Model (DOM) Level 2 Core Specification: Attributes with the name "ID" are not of type ID unless so defined. Implementations that do not know whether attributes are of type ID or not are expected to return null. That means that DomDocument->get_document_by_id("X") and XPathContext->xpath_eval("//*[@id='X']) are not equivalent and that the former function should only return a result if a DTD is referenced which declares attributes of type ID.