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

Update: I’ve fixed this by implementing two new methods, childElementsWithCSSSelector and selectChildElements, for restricting CSS selector searches to just the children of the specified element.

You have a pull request :)

Original post follows:

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 (both children of that b element and siblings of b):

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 node and its children only (not siblings) but this doesn’t appear to be the case.

Clone this wiki locally