note 89771 added to class.domxpath
| From: | ahsdg at ftp dot pochta dot ru | Date: | Sun, 22 Mar 2009 23:39:20 +0000 |
| Subject: | note 89771 added to class.domxpath | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-152308@lists.php.net to get a copy of this message | ||
For more then one search this function will be helpfull:
<?php
class xpathExtension{
public static function getNodes($domDoc, $xpathString) {
$xp = new DOMXPath($domDoc);
$xp->registerNamespace('x', 'http://www.w3.org/1999/xhtml');
$xp->registerNamespace('xhtml', 'http://www.w3.org/1999/xhtml');
$xp->registerNamespace('i18n', 'http://apache.org/cocoon/i18n/2.1');
$ret = array();
$nodes = $xp->query($xpathString);
foreach ($nodes as $node) {
array_push($ret, $node);
}
return $ret;
}
}
$domDoc = new DOMDocument();
$domDoc->load("xmlFile.xml");
$xpathString = "//html/body/*[@class='text']";
$domNodeList = xpathExtension::getNodes($domDoc, $xpathString);
foreach($domNodeList as $domNode){
echo $domNode->nodeName;
}
?>
Thanks to:
https://svn.liip.ch/repos/public/okapi/core/trunk/inc/api/helpers/
xpath.php
----
Server IP: 217.13.201.10
Probable Submitter: 93.129.59.175
----
Manual Page -- http://www.php.net/manual/en/class.domxpath.php
Edit -- https://master.php.net/note/edit/89771
Del: integrated -- https://master.php.net/note/delete/89771/integrated
Del: useless -- https://master.php.net/note/delete/89771/useless
Del: bad code -- https://master.php.net/note/delete/89771/bad+code
Del: spam -- https://master.php.net/note/delete/89771/spam
Del: non-english -- https://master.php.net/note/delete/89771/non-english
Del: in docs -- https://master.php.net/note/delete/89771/in+docs
Del: other reasons-- https://master.php.net/note/delete/89771
Reject -- https://master.php.net/note/reject/89771
Search -- https://master.php.net/manage/user-notes.php