Re: PHP5, XPath and count()

From: Date: Wed, 21 Jul 2004 08:57:50 +0000
Subject: Re: PHP5, XPath and count()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-191285@lists.php.net to get a copy of this message
On Tue, 20 Jul 2004 22:57:20 +0200, Victor Boivie <vicbo261@student.liu.se> wrote: > 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)); this doesn't work yet in DOM. The returned value has to be a nodeset. Will be fixed some day ;) see victors answer for the work around chregu > > ... returns NULL. > > Any ideas? > > Thanks in advance, > Victor > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- 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 0x5CE1DECB

« previous php.general (#191285) next »