Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • julius 107 posts 289 karma points
    Oct 15, 2011 @ 18:47
    julius
    0

    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?

     

     

     

     

  • Rodion Novoselov 694 posts 859 karma points
    Oct 15, 2011 @ 19:28
    Rodion Novoselov
    0

    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.

  • julius 107 posts 289 karma points
    Oct 15, 2011 @ 19:47
    julius
    0

    Great, I changed the query to

     

    /descendant::* [@id = -1]/descendant-or-self::* [@isDoc and @nodeType = 1058]

     

    This works.

     

Please Sign in or register to post replies

Write your reply to:

Draft