Copied to clipboard

Flag this post as spam?

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


  • Michael Stanley 7 posts 27 karma points
    May 05, 2010 @ 14:38
    Michael Stanley
    0

    How do I get sibling nodes?

    I have a content tree that looks like this:

    <Content>
        <NodeA>
            <NodeA1/>
            <NodeA2/>
            <NodeA3/>
        </NodeA>
        <NodeB>
            <NodeB1/>
            <NodeB2/>
        </NodeB>
    </Content>

    I am trying to use the nodeFactory to navigate this tree. If my current node is NodeA2 and I want to get to NodeB2, I thought I could do something like this:

    Node root = Node.GetCurrent();
    while(root.Parent != null)
        root = root.Parent;

    Node NodeB2 = root.Children[1].Children[1];

    However, the loop to get the root node stops at NodeA because the parent of NodeA is null. How am I supposed to get to the sibling nodes?

  • Michael Stanley 7 posts 27 karma points
    May 05, 2010 @ 14:51
    Michael Stanley
    0

    It looks like this:

    Node root = new Node(-1);

    will get the Content node and NodeA and NodeB are both children. A little weird since all the nodes are children of the Content node but the Content node is not a parent of its children???

  • Chris Dunn 210 posts 401 karma points
    May 05, 2010 @ 17:01
    Chris Dunn
    0

    Just my thoughts.  The root node is not a traditional node.  If you check the database the parent of the root node is also -1, the root node.  And in the data/umbraco.config it is specified as <root> vs <node>.  So since it's not a traditional node, it functions a little bit differently.

    -Chris

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies