Skip to content
aral edited this page Sep 13, 2010 · 8 revisions

If I have a structure:

<a>
    <b></b>
    <b></b>
    <b>
        <b>
        </b>
    </b>
</a>

Where b nodes may contain other b nodes, I can get an NSArray of b nodes with NSArray *elements = [doc selectElements:@"a > b"]. However, when I want to loop through those elements to get their child b elements, I’m getting the full list of b elements:

for (Element *element in elements) {
    // This should only get second-level b elements but doesn't.
    childBElements = [element selectElements:@"b"];
   NSLog(@"%@", childBElements);
}

I would expect selectors on a node to be scoped to that nope and its children but it appears that the selectors are firing globally? Would love some feedback on this, if only to prove that I’m not going mad :)

Update: It looks like selectElements is not just returning the elements that element contains but also siblings from that elements onwards.

Clone this wiki locally