What's the difference between these XPath queries?
Hello,
In my .NET control I tested these two queries
/root/descendant::* [@id = 5411]/descendant-or-self::* [@isDoc and (@nodeType = 1058)]
/root/descendant::* [@id = -1]/descendant-or-self::* [@isDoc and @nodeType = 1058]
I fire these queries with XPathNodeIterator iterator = library.GetXmlNodeByXPath(myQuery);
The first queries yields what I need, a list of six nodes of type 1058 that reside under the node with id 5411, but not directly under 5411. Node 5411 is a "Section" and under the Section is a "Folder" and under that folder are my six "Theme" nodes. So far so good!
The second query however yields.... nothing and I don't understand why.
I thought both queries should search nodes that conform to the nodeType restrictions and are descendants of 5411 (first query) or -1 (second query). So, shouldn't this boil down to the same result? I mean, in both cases my Theme/1058 nodes are descendants of..............
Owww...... while typing this message I might actually all of a sudden see why the second query doesn't work :) Could this be the problem:
The second query first selects the root with /root/descendant and subsequently nodes UNDER the root with id -1, always resulting in ... nothing, because there is no node under the root with id -1?
Hello. Yeah, you are right. You've already aswered your question on your own. The 'root' node itself has an id of '-1' (you can prove it simply taking a look into the umbraco.config file) . So /root/descendant::*[@id = -1] evaluates to an empty node set. However if it had read /root/descendant-or-self::*[@id = -1] it would have evaluated to the /root node itself.
What's the difference between these XPath queries?
Hello,
In my .NET control I tested these two queries
/root/descendant::* [@id = 5411]/descendant-or-self::* [@isDoc and (@nodeType = 1058)]
/root/descendant::* [@id = -1]/descendant-or-self::* [@isDoc and @nodeType = 1058]
I fire these queries with XPathNodeIterator iterator = library.GetXmlNodeByXPath(myQuery);
The first queries yields what I need, a list of six nodes of type 1058 that reside under the node with id 5411, but not directly under 5411. Node 5411 is a "Section" and under the Section is a "Folder" and under that folder are my six "Theme" nodes. So far so good!
The second query however yields.... nothing and I don't understand why.
I thought both queries should search nodes that conform to the nodeType restrictions and are descendants of 5411 (first query) or -1 (second query). So, shouldn't this boil down to the same result? I mean, in both cases my Theme/1058 nodes are descendants of..............
Owww...... while typing this message I might actually all of a sudden see why the second query doesn't work :) Could this be the problem:
The second query first selects the root with /root/descendant and subsequently nodes UNDER the root with id -1, always resulting in ... nothing, because there is no node under the root with id -1?
Hello. Yeah, you are right. You've already aswered your question on your own. The 'root' node itself has an id of '-1' (you can prove it simply taking a look into the umbraco.config file) . So /root/descendant::*[@id = -1] evaluates to an empty node set. However if it had read /root/descendant-or-self::*[@id = -1] it would have evaluated to the /root node itself.
Great, I changed the query to
/descendant::* [@id = -1]/descendant-or-self::* [@isDoc and @nodeType = 1058]
This works.
is working on a reply...