note 121043 added to class.domxpath
| From: | peter at softcoded dot com | Date: | Wed, 03 May 2017 17:51:06 +0000 |
| Subject: | note 121043 added to class.domxpath | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-209047@lists.php.net to get a copy of this message | ||
You may not always know at runtime whether your file has
a namespace or not. This can make it difficult to create
XPath queries. Use the seriously underdocumented
"namespaceURI" property of the documentElement of a
DOMDocument to determine if there is a namespace.
Use code such as the following:
$doc = new DOMDocument();
$doc->load($file);
$xpath = new DOMXPath($doc);
$ns = $doc->documentElement->namespaceURI;
if($ns) {
$xpath->registerNamespace("ns", $ns);
$nodes = $xpath->query("//ns:em[@class='glossterm']");
} else {
$nodes = $xpath->query("//em[@class='glossterm']");
}
//look at nodes here
----
Server IP: 72.52.91.14
Probable Submitter: 23.249.203.110
----
Manual Page -- http://php.net/manual/en/class.domxpath.php
Edit -- https://master.php.net/note/edit/121043
Del: integrated -- https://master.php.net/note/delete/121043/integrated
Del: useless -- https://master.php.net/note/delete/121043/useless
Del: bad code -- https://master.php.net/note/delete/121043/bad+code
Del: spam -- https://master.php.net/note/delete/121043/spam
Del: non-english -- https://master.php.net/note/delete/121043/non-english
Del: in docs -- https://master.php.net/note/delete/121043/in+docs
Del: other reasons-- https://master.php.net/note/delete/121043
Reject -- https://master.php.net/note/reject/121043
Search -- https://master.php.net/manage/user-notes.php