note 121041 added to class.domxpath
| From: | peter at softcoded dot com | Date: | Wed, 03 May 2017 16:46:17 +0000 |
| Subject: | note 121041 added to class.domxpath | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-209045@lists.php.net to get a copy of this message | ||
Using XPath expressions can save a lot of programming
and allow you to home in on only the nodes you want.
Suppose you want to delete all empty <p> tags.
If you create a query using the following XPath expression,
you can find <p> tags that do not have any text
(other than spaces), any attributes,
any children or comments:
$expression = "//p[not(@*)
and not(*)
and not(./comment())
and normalize-space(text())='']";
This expression will only find para tags that look like:
<p>[any number of spaces]</p>
<p></p>
Imagine the code you would have to add if you used
DOMDocument::getElementsByTagName("p") instead.
----
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/121041
Del: integrated -- https://master.php.net/note/delete/121041/integrated
Del: useless -- https://master.php.net/note/delete/121041/useless
Del: bad code -- https://master.php.net/note/delete/121041/bad+code
Del: spam -- https://master.php.net/note/delete/121041/spam
Del: non-english -- https://master.php.net/note/delete/121041/non-english
Del: in docs -- https://master.php.net/note/delete/121041/in+docs
Del: other reasons-- https://master.php.net/note/delete/121041
Reject -- https://master.php.net/note/reject/121041
Search -- https://master.php.net/manage/user-notes.php