Add Document methods to access the root, head & body elements
The implementation will be changed/adapted later when the CSS Selectors are ready.
This commit is contained in:
@@ -27,6 +27,12 @@ typedef NS_ENUM(short, HTMLDocumentReadyState)
|
||||
|
||||
@property (nonatomic, assign, readonly) HTMLDocumentReadyState readyState;
|
||||
|
||||
@property (nonatomic, strong) HTMLElement *rootElement;
|
||||
|
||||
@property (nonatomic, strong) HTMLElement *head;
|
||||
|
||||
@property (nonatomic, strong) HTMLElement *body;
|
||||
|
||||
+ (instancetype)documentWithString:(NSString *)string;
|
||||
|
||||
- (HTMLNode *)adoptNode:(HTMLNode *)node;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#import "HTMLDocument.h"
|
||||
#import "HTMLParser.h"
|
||||
#import "HTMLNodeIterator.h"
|
||||
#import "HTMLKitDOMExceptions.h"
|
||||
|
||||
@interface HTMLNode (Private)
|
||||
@@ -66,6 +67,53 @@
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (HTMLElement *)rootElement
|
||||
{
|
||||
for (HTMLNode *node = self.firstChiledNode; node; node = node.nextSibling) {
|
||||
if (node.nodeType == HTMLNodeElement) {
|
||||
return node.asElement;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)setRootElement:(HTMLElement *)rootElement
|
||||
{
|
||||
[self replaceChildNode:self.rootElement withNode:rootElement];
|
||||
}
|
||||
|
||||
- (HTMLElement *)head
|
||||
{
|
||||
for (HTMLNode *node in [self nodeIteratorWithFilter:nil showOptions:HTMLNodeFilterShowElement]) {
|
||||
if ([node.asElement.tagName isEqualToString:@"head"]) {
|
||||
return node.asElement;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)setHead:(HTMLElement *)head
|
||||
{
|
||||
[self replaceChildNode:self.head withNode:head];
|
||||
}
|
||||
|
||||
- (HTMLElement *)body
|
||||
{
|
||||
for (HTMLNode *node in [self nodeIteratorWithFilter:nil showOptions:HTMLNodeFilterShowElement]) {
|
||||
if ([node.asElement.tagName isEqualToString:@"body"]) {
|
||||
return node.asElement;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)setBody:(HTMLElement *)body
|
||||
{
|
||||
[self replaceChildNode:self.body withNode:body];
|
||||
}
|
||||
|
||||
#pragma mark - Node Iterators
|
||||
|
||||
- (void)attachNodeIterator:(HTMLNodeIterator *)iterator
|
||||
|
||||
Reference in New Issue
Block a user