note 73557 modified in domxpath.query by mikemike
| From: | mikemike@php.net | Date: | Thu, 14 Feb 2013 16:48:11 +0000 |
| Subject: | note 73557 modified in domxpath.query by mikemike | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-193635@lists.php.net to get a copy of this message | ||
If you want to perform queries on XHTML documents, you must fix a default namespace:
<?php
$doc = new DOMDocument;
$doc->preserveWhiteSpace = true;
$doc->resolveExternals = true; // for character entities
$doc->load("http://www.w3.org/");
$xpath = new DOMXPath($doc);
// won't work
$entries = $xpath->query("//div");
// you should use :
$xpath->registerNamespace("html", "http://www.w3.org/1999/xhtml");
$entries = $xpath->query("//html:div");
?>
--was--
If you want to perform queries on XHTML documents, you must fix a default namespace:
$doc = new DOMDocument;
$doc->preserveWhiteSpace = true;
$doc->resolveExternals = true; // for character entities
$doc->load("http://www.w3.org/");
$xpath = new DOMXPath($doc);
// won't work
$entries = $xpath->query("//div");
// you should use :
$xpath->registerNamespace("html", "http://www.w3.org/1999/xhtml");
$entries = $xpath->query("//html:div");
http://php.net/manual/en/domxpath.query.php