Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

XPath

Moderators: kris

Posted: 02/26/08 15:18:54

I just tried XPath from the xml package, but I cannot see a way to duplicate my queries. The documentation says to use .dup on the NodeSet?, but this isn't implemented. So either the documentation is wrong and there is another way of doing this, or .dup is missing.

From the documentation:

Note that path queries are temporal - they do not retain content across mulitple queries. For example:

        auto elements = doc.query["element"];
        auto children = elements["child"];

The above will clobber 'elements', because the document reuses node space for subsequent queries. In order to retain queries, do this:

        auto elements = doc.query["element"].dup;
        auto children = elements["child"];
Author Message

Posted: 02/26/08 15:23:43

And it would have been nice to be able to get a node directly from a NodeSet?.
Node getNode(int index) would be sufficient.

Posted: 02/26/08 18:18:11 -- Modified: 02/26/08 18:18:36 by
kris

Methods NodeSet.nth(x), along with first() and last() are already there. Opened up access to the 'members' attribute, so you can also use array-slicing on it as a Node[]. Added NodeSet.dup also (which used to work, but ...)

Please let us know how you get on?

Posted: 02/26/08 19:18:40

Will be renaming 'members' to be 'nodes' instead

Posted: 02/27/08 09:03:28

Great, just what I needed!