Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add -children to TFHppleElement to get a node's children
  • Loading branch information
Zach Drayer committed Jul 10, 2011
1 parent e4db033 commit a49d5fe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions TFHppleElement.h
Expand Up @@ -50,6 +50,9 @@
// class = 'highlight'
- (NSDictionary *) attributes;

// Returns the children of a given node
- (NSArray *) children;

// Provides easy access to the content of a specific attribute,
// such as 'href' or 'class'.
- (NSString *) objectForKey:(NSString *) theKey;
Expand Down
11 changes: 11 additions & 0 deletions TFHppleElement.m
Expand Up @@ -32,6 +32,7 @@

static NSString * const TFHppleNodeContentKey = @"nodeContent";
static NSString * const TFHppleNodeNameKey = @"nodeName";
static NSString * const TFHppleNodeChildrenKey = @"nodeChildArray";
static NSString * const TFHppleNodeAttributeArrayKey = @"nodeAttributeArray";
static NSString * const TFHppleNodeAttributeNameKey = @"attributeName";

Expand Down Expand Up @@ -71,6 +72,16 @@ - (NSString *) tagName
return [node objectForKey:TFHppleNodeNameKey];
}

- (NSArray *) children
{
NSMutableArray *children = [NSMutableArray array];
for (NSDictionary *child in [node objectForKey:TFHppleNodeChildrenKey]) {
TFHppleElement *element = [TFHppleElement hppleElementWithNode:child];
[children addObject:element];
}
return children;
}

- (NSDictionary *) attributes
{
NSMutableDictionary * translatedAttributes = [NSMutableDictionary dictionary];
Expand Down

0 comments on commit a49d5fe

Please sign in to comment.