# domxpath->query: bug or not?

- Thread: https://externals.io/message/7976
- Original archive: https://news-web.php.net/php.internals/7976
- Started by Banyai Zsolt on 2004-02-18T22:09:07+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #7976 — Banyai Zsolt — 2004-02-18T22:09:07+00:00

URL: https://externals.io/message/7976#7976

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

---

## #7977 — Rob Richards — 2004-02-18T22:46:02+00:00

URL: https://externals.io/message/7976#7977 · In reply to: #7976

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
