Re: DomXPath extension
| From: | Christian Stocker | Date: | Sat, 24 Jul 2004 08:47:47 +0000 |
| Subject: | Re: DomXPath extension | ||
| References: | 1 2 3 | Groups: | php.xml.dev |
| Request: | Send a blank email to php-xml-dev+get-430@lists.php.net to get a copy of this message | ||
Rob and me were talking about that the other day. I don't think that anyone is working right now on it, but we at least decided on the API for it. It should be loosely based on the W3C specs (http://www.w3.org/TR/2004/NOTE-DOM-Level-3-XPath-20040226/xpath.html#XPathEvaluator ), for example:
$xp = new DomXPath($doc);
$xp->evaluate($xpathExpression[, $contextnode [, $type]]);
This can all go into ext/dom/xpath.c, no need for writing a new extension. And Jason, you're of course very welcome to extend this. It shouldn't be that hard, with the already existing code as a template.
And query() will never return a number instead of a nodeset, for backwards compatibility reasons, we'd rather introduce a new method name "evaluate" like explained above.
chregu
On 24.7.2004 4:18 Uhr, Jason Barnett wrote:
-- christian stocker | Bitflux GmbH | schoeneggstrasse 5 | ch-8004 zurich phone +41 1 240 56 70 | mobile +41 76 561 88 60 | fax +41 1 240 56 71 http://www.bitflux.ch | chregu@bitflux.ch | gnupg-keyid 0x5CE1DECBThis is the PHP 5 DOMXPath class? It just passes XPath queries to libxml2, so it should support everything you want. What specifically are you missing? -adamYes, I mean PHP5 DOMXPath. OK, here's a sample script: <?php $xml = <<<XML <music> <artist id="1"><name>The Rolling Stones</name> <albums> <title>Exile On Main Street</title> </albums></artist> <artist id="2"><name>Aimee Mann</name> <albums> <title>I'm With Stupid</title> <title>Bachelor No. 2</title> </albums></artist> </music> XML; $dom = new DomDocument(); $dom->loadXML($xml); $xpath = new DomXpath($dom); var_dump($xpath->query("count(//music/artist)")); ?> Result of the var_dump (php5.0.0): object(DOMNodeList)#3 (0) { } I expected to get a number (2), but Chrisitan told me before that right now query will only return DOMNodeList's. A workaround is to query for the nodes (//music/artist) and then use PHP's count() function, but I was wondering when query will actually return a number instead of a nodelist.