Re: DomXPath extension

From: Date: Sat, 24 Jul 2004 02:18:57 +0000
Subject: Re: DomXPath extension
References: 1 2  Groups: php.xml.dev 
Request: Send a blank email to php-xml-dev+get-429@lists.php.net to get a copy of this message
This 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? -adam
Yes, 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.

« previous php.xml.dev (#429) next »