in

ArtOfTest, Inc. Community Forums

Discuss and ask questions about ArtOfTest's products.

Getting a tag's sibling (next/previous) - navigate 'sideways'

Last post 03-12-2008 5:39 PM by djmarcus. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 02-05-2008 7:00 PM

    Getting a tag's sibling (next/previous) - navigate 'sideways'

    It would be very useful to be able to navigate 'sideways'. This is the ability to find a sibling tag based on criteria (such as tag name, attributes, content, inner text, ...).

     

    Something like:

        Find.SiblingById(...Find parms..., direction)   - where 'direction' is some enum for next/previous

    or

        Find.NextSiblingById(...Find parms...)  - finds sibling going forward ("next")

        Find.PreviousSiblingById(...Find parms...) - finds sibling going backwards ("previous")

     

    Functions would return null if not found.

    Functions should be parameterized as in:

       Find.SiblingById<T>(...)

     

    In the absence of this feature, I actually implemented this for my own usage.

     

    -David
     

  • 03-12-2008 4:39 PM In reply to

    • Chris
    • Top 10 Contributor
    • Joined on 06-14-2007
    • Posts 82

    Re: Getting a tag's sibling (next/previous) - navigate 'sideways'

    Thanks for the feedback! 

    You can use something like this to get the next sibling:

    Element foo;

    foo.Parent.Children[foo.AbsoluteSiblingTagIndex + 1];

    or previous:

    Element foo;

    foo.Parent.Children[foo.AbsoluteSiblingTagIndex - 1];

    Chris

    ArtOfTest, Inc.
  • 03-12-2008 5:39 PM In reply to

    Re: Getting a tag's sibling (next/previous) - navigate 'sideways'

    I was quite aware of the AbsoluteSiblingTagIndex property (its neat), but it does not solve the general problem of being able to select the 'next/previous' sibling by some criteria other than just that the sibling is physically adjacent.

    I have run into situations where I want the next sibling that is, for example, a <P> node and where that node may not necessarily be the physically adjacent node.

     A separate issue, at least for me, is that the AbsoluteSiblingTagIndex property is based on 'Children' rather than 'ChildNodes' and thus excludes any of the '#' tags (#text#, #comment#). In some cases I really do want to get the next tag in 'ChildNodes' rather than just 'Children'.

    So, my wish is still for some general search capabilities that allow me to fully 'navigate' the DOM laterally based on the same type of criteria available for vertical navigation.

    -David
     

Page 1 of 1 (3 items)
Copyrights © 2008 ArtOfTest, Inc. All rights reserved.