forked from spawrks/Objective-C-HMTL-Parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HTMLNode.h
111 lines (83 loc) · 2.64 KB
/
HTMLNode.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//
// HTMLNode.h
// StackOverflow
//
// Created by Ben Reeves on 09/03/2010.
// Copyright 2010 Ben Reeves. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <libxml/HTMLparser.h>
#import "HTMLParser.h"
@class HTMLParser;
#define ParsingDepthUnlimited 0
#define ParsingDepthSame -1
#define ParsingDepth size_t
typedef enum
{
HTMLHrefNode,
HTMLTextNode,
HTMLUnkownNode,
HTMLCodeNode,
HTMLSpanNode,
HTMLPNode,
HTMLLiNode,
HTMLUlNode,
HTMLImageNode,
HTMLOlNode,
HTMLStrongNode,
HTMLPreNode,
HTMLBlockQuoteNode,
} HTMLNodeType;
@interface HTMLNode : NSObject
{
@public
xmlNode * _node;
}
//Init with a lib xml node (shouldn't need to be called manually)
//Use [parser doc] to get the root Node
-(id)initWithXMLNode:(xmlNode*)xmlNode;
//Returns a single child of class
-(HTMLNode*)findChildOfClass:(NSString*)className;
//Returns all children of class
-(NSArray*)findChildrenOfClass:(NSString*)className;
//Finds a single child with a matching attribute
//set allowPartial to match partial matches
//e.g. <img src="http://www.google.com> [findChildWithAttribute:@"src" matchingName:"google.com" allowPartial:TRUE]
-(HTMLNode*)findChildWithAttribute:(NSString*)attribute matchingName:(NSString*)className allowPartial:(BOOL)partial;
//Finds all children with a matching attribute
-(NSArray*)findChildrenWithAttribute:(NSString*)attribute matchingName:(NSString*)className allowPartial:(BOOL)partial;
//Gets the attribute value matching tha name
-(NSString*)getAttributeNamed:(NSString*)name;
//Find childer with the specified tag name
-(NSArray*)findChildTags:(NSString*)tagName;
//Looks for a tag name e.g. "h3"
-(HTMLNode*)findChildTag:(NSString*)tagName;
//Returns the first child element
-(HTMLNode*)firstChild;
//Returns the plaintext contents of node
-(NSString*)contents;
//Returns the plaintext contents of this node + all children
-(NSString*)allContents;
//Returns the html contents of the node
-(NSString*)rawContents;
//Returns next sibling in tree
-(HTMLNode*)nextSibling;
//Returns previous sibling in tree
-(HTMLNode*)previousSibling;
//Returns the class name
-(NSString*)className;
//Returns the tag name
-(NSString*)tagName;
//Returns the parent
-(HTMLNode*)parent;
//Returns the first level of children
-(NSArray*)children;
//Returns the node type if know
-(HTMLNodeType)nodetype;
//C functions for minor performance increase in tight loops
NSString * getAttributeNamed(xmlNode * node, const char * nameStr);
void setAttributeNamed(xmlNode * node, const char * nameStr, const char * value);
HTMLNodeType nodeType(xmlNode* node);
NSString * allNodeContents(xmlNode*node);
NSString * rawContentsOfNode(xmlNode * node);
@end