note 32428 deleted from function.xpath-new-context by sobak
| From: | sobak@php.net | Date: | Tue, 22 Nov 2016 03:40:44 +0000 |
| Subject: | note 32428 deleted from function.xpath-new-context by sobak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-207400@lists.php.net to get a copy of this message | ||
Note Submitter:
----
I found a nice function in XML_sql2xml. With it, you can get, easily, the result of a xpath
expression.
function getXpathValues(&$dom, $expr) {
$xpth = $dom->xpath_new_context();
$xnode = xpath_eval($xpth,$expr);
if (isset ($xnode->nodeset[0])) {
$firstnode = $xnode->nodeset[0];
$children = $firstnode->children();
$value = $children[0]->content;
return $value;
}
else return Null;
}
Usage :
$dom = domxml_open_file('pear.rss');
echo $this->getXpathValues($dom, "//channel/title");