Re: PHP5, XPath and count()

From: Date: Wed, 21 Jul 2004 03:31:24 +0000
Subject: Re: PHP5, XPath and count()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-191259@lists.php.net to get a copy of this message
To find the number of nodes in a DomNodeList you need to access the length property... sample code to do this: <?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); $nodelist = $xpath->query('/music/artist'); print $nodelist->length; ?>

« previous php.general (#191259) next »