forked from stklieme/HTMLDocument
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTMLNode+XPath.h
More file actions
324 lines (271 loc) · 15.2 KB
/
Copy pathHTMLNode+XPath.h
File metadata and controls
324 lines (271 loc) · 15.2 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/*###################################################################################
# #
# HTMLNode+XPath.h #
# Category of HTMLNode for XPath support #
# #
# Copyright © 2011-2013 by Stefan Klieme #
# #
# Objective-C wrapper for HTML parser of libxml2 #
# #
# Version 1.6 - 29. Sep 2013 #
# #
# usage: add #import HTMLNode+XPath.h #
# #
# #
####################################################################################
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy of #
# this software and associated documentation files (the "Software"), to deal #
# in the Software without restriction, including without limitation the rights #
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies #
# of the Software, and to permit persons to whom the Software is furnished to do #
# so, subject to the following conditions: #
# The above copyright notice and this permission notice shall be included in #
# all copies or substantial portions of the Software. #
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,#
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR #
# IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #
# #
###################################################################################*/
#import "HTMLNode.h"
#if !defined(__clang__) || __clang_major__ < 3
#ifndef __bridge_retained
#define __bridge_retained
#endif
#ifndef __bridge_transfer
#define __bridge_transfer
#endif
#endif
@interface HTMLNode (XPath)
// Xpath query methods
/*! Returns the first descendant node for a XPath query
* \param query The XPath query string
* \param error An error object that, on return, identifies any Xpath errors.
* \returns The first found descendant node or nil if no node matches the parameters
*/
- (HTMLNode *)nodeForXPath:(NSString *)query error:(NSError **)error;
/*! Returns the first descendant node for a XPath query
* \param query The XPath query string
* \returns The first found descendant node or nil if no node matches the parameters
*/
- (HTMLNode *)nodeForXPath:(NSString *)query;
/*! Returns all descendant nodes for a XPath query
* \param query The XPath query string
* \param error An error object that, on return, identifies any Xpath errors.
* \returns The array of all found descendant nodes or an empty array
*/
- (NSArray *)nodesForXPath:(NSString *)query error:(NSError **)error;
/*! Returns all descendant nodes for a XPath query
* \param query The XPath query string
* \returns The array of all found descendant nodes or an empty array
*/
- (NSArray *)nodesForXPath:(NSString *)query;
// Note: In the HTMLNode main class all appropriate query methods begin with descendant instead of node
/*! Returns the first descendant node for a specified tag name
* \param tagName The tag name
* \param error An error object that, on return, identifies any Xpath errors.
* \returns The first found descendant node or nil if no node matches the parameters
*/
- (HTMLNode *)nodeOfTag:(NSString *)tagName error:(NSError **)error;
/*! Returns the first descendant node for a specified tag name
* \param tagName The tag name
* \returns The first found descendant node or nil if no node matches the parameters
*/
- (HTMLNode *)nodeOfTag:(NSString *)tagName;
/*! Returns all descendant nodes for a specified tag name
* \param tagName The tag name
* \param error An error object that, on return, identifies any Xpath errors.
* \returns The array of all found descendant nodes or an empty array
*/
- (NSArray *)nodesOfTag:(NSString *)tagName error:(NSError **)error;
/*! Returns all descendant nodes for a specified tag name
* \param tagName The tag name
* \returns The array of all found descendant nodes or an empty array
*/
- (NSArray *)nodesOfTag:(NSString *)tagName;
/*! Returns the first descendant node for a matching tag name and matching attribute name
* \param tagName The tag name
* \param attributeName The attribute name
* \param error An error object that, on return, identifies any Xpath errors.
* \returns The first found descendant node or nil if no node matches the parameters
*/
- (HTMLNode *)nodeOfTag:(NSString *)tagName withAttribute:(NSString *)attributeName error:(NSError **)error;
/*! Returns the first descendant node for a matching tag name and matching attribute name
* \param tagName The tag name
* \param attributeName The attribute name
* \returns The first found descendant node or nil if no node matches the parameters
*/
- (HTMLNode *)nodeOfTag:(NSString *)tagName withAttribute:(NSString *)attributeName;
/*! Returns all descendant nodes for a matching tag name and matching attribute name
* \param tagName The tag name
* \param attributeName The attribute name
* \param error An error object that, on return, identifies any Xpath errors.
* \returns The array of all found descendant nodes or an empty array
*/
- (NSArray *)nodesOfTag:(NSString *)tagName withAttribute:(NSString *)attributeName error:(NSError **)error;
/*! Returns all descendant nodes for a matching tag name and matching attribute name
* \param tagName The tag name
* \param attributeName The attribute name
* \param error An error object that, on return, identifies any Xpath errors.
* \returns The array of all found descendant nodes or an empty array
*/
- (NSArray *)nodesOfTag:(NSString *)tagName withAttribute:(NSString *)attributeName;
/*! Returns the first descendant node for a specified attribute name
* \param attributeName The attribute name
* \param error An error object that, on return, identifies any Xpath errors.
* \returns The first found descendant node or nil if no node matches the parameters
*/
- (HTMLNode *)nodeWithAttribute:(NSString *)attributeName error:(NSError **)error;
/*! Returns the first descendant node for a specified attribute name
* \param attributeName The attribute name
* \returns The first found descendant node or nil if no node matches the parameters
*/
- (HTMLNode *)nodeWithAttribute:(NSString *)attributeName;
/*! Returns all descendant nodes for a specified attribute name
* \param attributeName The attribute name
* \returns The array of all found descendant nodes or an empty array
*/
- (NSArray *)nodesWithAttribute:(NSString *)attributeName error:(NSError **)error;
/*! Returns all descendant nodes for a specified attribute name
* \param attributeName The attribute name
* \param error An error object that, on return, identifies any Xpath errors.
* \returns The array of all found descendant nodes or an empty array
*/
- (NSArray *)nodesWithAttribute:(NSString *)attributeName;
/*! Returns the first descendant node for a matching attribute name and matching attribute value
* \param attributeName The attribute name
* \param value The attribute value
* \param error An error object that, on return, identifies any Xpath errors.
* \returns The first found descendant node or nil if no node matches the parameters
*/
- (HTMLNode *)nodeWithAttribute:(NSString *)attributeName valueMatches:(NSString *)value error:(NSError **)error;
/*! Returns the first descendant node for a matching attribute name and matching attribute value
* \param attributeName The attribute name
* \param value The attribute value
* \returns The first found descendant node or nil if no node matches the parameters
*/
- (HTMLNode *)nodeWithAttribute:(NSString *)attributeName valueMatches:(NSString *)value;
/*! Returns all descendant nodes for a matching attribute name and matching attribute value
* \param attributeName The attribute name
* \param value The attribute value
* \param error An error object that, on return, identifies any Xpath errors.
* \returns The array of all found descendant nodes or an empty array
*/
- (NSArray *)nodesWithAttribute:(NSString *)attributeName valueMatches:(NSString *)value error:(NSError **)error;
/*! Returns all descendant nodes for a matching attribute name and matching attribute value
* \param attributeName The attribute name
* \param value The attribute value
* \returns The array of all found descendant nodes or an empty array
*/
- (NSArray *)nodesWithAttribute:(NSString *)attributeName valueMatches:(NSString *)value;
/*! Returns the first descendant node for a matching attribute name and beginning of the attribute value
* \param attributeName The attribute name
* \param value The attribute value
* \param error An error object that, on return, identifies any Xpath errors.
* \returns The first found descendant node or nil if no node matches the parameters
*/
- (HTMLNode *)nodeWithAttribute:(NSString *)attributeName valueBeginsWith:(NSString *)value error:(NSError **)error;
/*! Returns the first descendant node for a matching attribute name and beginning of the attribute value
* \param attributeName The attribute name
* \param value The attribute value
* \returns The first found descendant node or nil if no node matches the parameters
*/
- (HTMLNode *)nodeWithAttribute:(NSString *)attributeName valueBeginsWith:(NSString *)value;
/*! Returns all descendant nodes for a matching attribute name and beginning of the attribute value
* \param attributeName The attribute name
* \param value The attribute value
* \param error An error object that, on return, identifies any Xpath errors.
* \returns The array of all found descendant nodes or an empty array
*/
- (NSArray *)nodesWithAttribute:(NSString *)attributeName valueBeginsWith:(NSString *)value error:(NSError **)error;
/*! Returns all descendant nodes for a matching attribute name and beginning of the attribute value
* \param attributeName The attribute name
* \param value The attribute value
* \returns The array of all found descendant nodes or an empty array
*/
- (NSArray *)nodesWithAttribute:(NSString *)attributeName valueBeginsWith:(NSString *)value;
/*! Returns the first descendant node for a matching attribute name and ending of the attribute value
* \param attributeName The attribute name
* \param value The attribute value
* \param error An error object that, on return, identifies any Xpath errors.
* \returns The first found descendant node or nil if no node matches the parameters
*/
- (HTMLNode *)nodeWithAttribute:(NSString *)attributeName valueEndsWith:(NSString *)value error:(NSError **)error;
/*! Returns the first descendant node for a matching attribute name and ending of the attribute value
* \param attributeName The attribute name
* \param value The attribute value
* \returns The first found descendant node or nil if no node matches the parameters
*/
- (HTMLNode *)nodeWithAttribute:(NSString *)attributeName valueEndsWith:(NSString *)value;
/*! Returns all descendant nodes for a matching attribute name and ending of the attribute value
* \param attributeName The attribute name
* \param value The attribute value
* \param error An error object that, on return, identifies any Xpath errors.
* \returns The array of all found descendant nodes or an empty array
*/
- (NSArray *)nodesWithAttribute:(NSString *)attributeName valueEndsWith:(NSString *)value error:(NSError **)error;
/*! Returns all descendant nodes for a matching attribute name and ending of the attribute value
* \param attributeName The attribute name
* \param value The attribute value
* \returns The array of all found descendant nodes or an empty array
*/
- (NSArray *)nodesWithAttribute:(NSString *)attributeName valueEndsWith:(NSString *)value;
/*! Returns the first descendant node for a matching attribute name and containing the attribute value
* \param attributeName The attribute name
* \param value The attribute value
* \param error An error object that, on return, identifies any Xpath errors.
* \returns The first found descendant node or nil if no node matches the parameters
*/
- (HTMLNode *)nodeWithAttribute:(NSString *)attributeName valueContains:(NSString *)value error:(NSError **)error;
/*! Returns the first descendant node for a matching attribute name and containing the attribute value
* \param attributeName The attribute name
* \param value The attribute value
* \returns The first found descendant node or nil if no node matches the parameters
*/
- (HTMLNode *)nodeWithAttribute:(NSString *)attributeName valueContains:(NSString *)value;
/*! Returns all descendant nodes for a matching attribute name and containing the attribute value
* \param attributeName The attribute name
* \param value The attribute value
* \param error An error object that, on return, identifies any Xpath errors.
* \returns The array of all found descendant nodes or an empty array
*/
- (NSArray *)nodesWithAttribute:(NSString *)attributeName valueContains:(NSString *)value error:(NSError **)error;
/*! Returns all descendant nodes for a matching attribute name and containing the attribute value
* \param attributeName The attribute name
* \param value The attribute value
* \returns The array of all found descendant nodes or an empty array
*/
- (NSArray *)nodesWithAttribute:(NSString *)attributeName valueContains:(NSString *)value;
/*! Returns the first descendant node for a specified class name
* \param classValue The class name
* \param error An error object that, on return, identifies any Xpath errors.
* \returns The first found descendant node or nil if no node matches the parameters
*/
- (HTMLNode *)nodeWithClass:(NSString *)classValue error:(NSError **)error;
/*! Returns the first descendant node for a specified class name
* \param classValue The class name
* \returns The first found descendant node or nil if no node matches the parameters
*/
- (HTMLNode *)nodeWithClass:(NSString *)classValue;
/*! Returns all descendant nodes for a specified class name
* \param classValue The class name
* \param error An error object that, on return, identifies any Xpath errors.
* \returns The array of all found descendant nodes or an empty array
*/
- (NSArray *)nodesWithClass:(NSString *)classValue error:(NSError **)error;
/*! Returns all descendant nodes for a specified class name
* \param classValue The class name
* \returns The array of all found descendant nodes or an empty array
*/
- (NSArray *)nodesWithClass:(NSString *)classValue;
// Compare two nodes w.r.t document order with XPath
/*! Returns a Boolean value that indicates whether the receiver is equal to another given object
* \param node The node with which to compare the receiver
* \returns YES if the receiver is equal to the node, otherwise NO. In effect returns NO if receiver is nil
*/
- (BOOL)isEqual:(HTMLNode *)node;
- (void)setErrorWithMessage:(NSString *)message andCode:(NSInteger)code;
@end