domxpath->query: bug or not?

php.internals

Bányai Zsolt

22 years ago
Hi, If I know well, the domxpath::query always returns with DOMNodeList. But if i write an expression like this: //node1/@attribute and i haven't got node1 node in the XML, the query return with false (boolean). But if i write an expression like this: //node1/@attr when i have node1 node but i haven't got attr attribute on that, the query return with an empty DOMNodeList. Here is a sample code: $doc = new DOMDocument(); $doc -> loadXML('<xml><node1 name="x"/></xml>'); $xp = new DOMXPath($doc); print "Expression1:\n"; var_dump( $xp -> query("//node1/@attr")); print "\nExpression2:\n"; var_dump( $xp -> query("//node2/@attr")); And the result: Expression1: object(domnodelist)#3 (0) { } Expression2: bool(false) If it's not a bug, please inform me about the details. Thanks: zsolt banyai zsolt.banyai@kirowski.com

Rob Richards

22 years ago
From: Banyai Zsolt
> If I know well, the domxpath::query always returns with DOMNodeList. But > if i write an expression like this: //node1/@attribute and i haven't > got node1 node in the XML, the query return with false (boolean). But if > i write an expression like this: //node1/@attr when i have node1 node > but i haven't got attr attribute on that, the query return with an empty > DOMNodeList. > > If it's not a bug, please inform me about the details.
Thanks, fixed now. left over code from pre-domnodelist stuff. will always return domnodelist now unless there is an error Rob