PHP5, XPath and count()
| From: | Victor Boivie | Date: | Tue, 20 Jul 2004 20:57:20 +0000 |
| Subject: | PHP5, XPath and count() | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-191237@lists.php.net to get a copy of this message | ||
Assume an XML file that looks like:
<catalog>
<cd>
..
</cd>
<cd>
..
</cd>
..
</catalog>
... and that I would like to know the number of CDs. An xpath expression would look like count(/catalog/cd), but how do I run this expression?
$dom = new DOMDocument();
$dom->load("catalog.xml");
$xpath = new DOMXpath($dom);
var_dump($xpath->query("count(/catalog/cd")->item(0));
... returns NULL.
Any ideas?
Thanks in advance,
Victor