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 (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. Would love some feedback on this, if only to prove that I’m not going mad :)

Clone this wiki locally