-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSimpleHttpClientFilterForXML.m
More file actions
55 lines (44 loc) · 1.25 KB
/
SimpleHttpClientFilterForXML.m
File metadata and controls
55 lines (44 loc) · 1.25 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
#import "SimpleHttpClientFilterForXML.h"
@implementation SimpleHttpClientFilterForXML
//----------------------------------------------------------------------------//
#pragma mark -- Internal --
//----------------------------------------------------------------------------//
- (NSData *)trimBlank:(NSData *)data
{
NSInteger length = [data length];
NSInteger count = 0;
for (
const unsigned char *source = [data bytes];
count < length;
source++, count++
) {
if ('<' == *source) {
break;
}
}
if (0 == count || length - 1 == count) {
return data;
}
return data = [data
subdataWithRange:NSMakeRange(count, [data length]-count)
];
}
//----------------------------------------------------------------------------//
#pragma mark -- APIs --
//----------------------------------------------------------------------------//
- (id)apply:(NSData *)data
{
data = [self trimBlank:data];
NSError *error = nil;
DDXMLDocument *xmlDocument = [[DDXMLDocument alloc]
initWithData:data
options:XML_PARSE_RECOVER
error:&error
];
[xmlDocument autorelease];
if (error) {
return nil;
}
return xmlDocument;
}
@end