Skip to content

Commit a49d5fe

Browse files
author
Zach Drayer
committed
Add -children to TFHppleElement to get a node's children
1 parent e4db033 commit a49d5fe

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

TFHppleElement.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
// class = 'highlight'
5151
- (NSDictionary *) attributes;
5252

53+
// Returns the children of a given node
54+
- (NSArray *) children;
55+
5356
// Provides easy access to the content of a specific attribute,
5457
// such as 'href' or 'class'.
5558
- (NSString *) objectForKey:(NSString *) theKey;

TFHppleElement.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
static NSString * const TFHppleNodeContentKey = @"nodeContent";
3434
static NSString * const TFHppleNodeNameKey = @"nodeName";
35+
static NSString * const TFHppleNodeChildrenKey = @"nodeChildArray";
3536
static NSString * const TFHppleNodeAttributeArrayKey = @"nodeAttributeArray";
3637
static NSString * const TFHppleNodeAttributeNameKey = @"attributeName";
3738

@@ -71,6 +72,16 @@ - (NSString *) tagName
7172
return [node objectForKey:TFHppleNodeNameKey];
7273
}
7374

75+
- (NSArray *) children
76+
{
77+
NSMutableArray *children = [NSMutableArray array];
78+
for (NSDictionary *child in [node objectForKey:TFHppleNodeChildrenKey]) {
79+
TFHppleElement *element = [TFHppleElement hppleElementWithNode:child];
80+
[children addObject:element];
81+
}
82+
return children;
83+
}
84+
7485
- (NSDictionary *) attributes
7586
{
7687
NSMutableDictionary * translatedAttributes = [NSMutableDictionary dictionary];

0 commit comments

Comments
 (0)