Groups | Blog | Home
all groups > dotnet xml > january 2007 >

dotnet xml : SelectNodes and xpath.



DeveloperX
1/19/2007 11:18:36 AM
SelectNodes under 1.1 is confusing me.

Imagine an xml file that looks like this. It's just an example:
<drive>
<dir a="a">
<file>aA</file>
<file>aB</file>
<dir a="ab">
<file>abA</file>
<dir a=abc>
<file>abcA</file>
</dir>
<dir a="b">
<file>bA</file>
</dir>
</drive>

If I selectnodes on //drive/dir I'd get a node list of two items dir's
a=a and a=b. So far so good.
Now I have a recursive method to which I pass each of the nodes in the
nodelist and attemp to selectnodes on the node to return any sub
directory. instead it operates on (I assume) the document property of
the node so we end up running out of stack.

Is there an xpath qualifier or way to selectnodes from a node without
starting at the top short of creating a new document based on the
node's outerxml?
thanks
DeveloperX
1/19/2007 2:11:48 PM
Gold star in the post :) Many thanks.


[quoted text, click to view]
Keith Patrick
1/19/2007 3:38:11 PM
The //drive is what's hosing you; it's an absolute path where you need a
relative one. You can SelectNodes on just //dir, and then any of those
nodes, you can just SelectNodes("dir") (or maybe "./dir"), as the XPath
relative references work very much like command line prompts in both Unix
and Windows.


AddThis Social Bookmark Button