-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJotParser.m
68 lines (56 loc) · 1.55 KB
/
JotParser.m
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
//
// JotParser.m
// Jotlr
//
// Created by Jeff Remer on 7/27/10.
// Copyright 2010 Widgetbox, Inc. All rights reserved.
//
#import "JotParser.h"
@implementation JotParser
@synthesize currentProperty,
currentJot;
#pragma mark Public Methods
- (id) initWithData:(NSData *)data {
[super initWithData:data];
[self setDelegate:self];
[self setShouldProcessNamespaces:NO];
[self setShouldReportNamespacePrefixes:NO];
return self;
}
- (Jot *) parseJot {
[self parse];
return self.currentJot;
}
#pragma mark -
#pragma mark Parsing Data
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if (self.currentProperty) {
[self.currentProperty appendString:string];
}
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
if (qName) {
elementName = qName;
}
if(self.currentJot) {
if ([elementName isEqualToString:@"permalink"]) {
self.currentProperty = [NSMutableString string];
}
} else {
if([elementName isEqualToString:@"jot"]) {
self.currentJot = [[Jot alloc] init];
}
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if (qName) {
elementName = qName;
}
if (self.currentJot) {
if ([elementName isEqualToString:@"permalink"]) {
self.currentJot.permalink = self.currentProperty;
}
}
self.currentProperty = nil;
}
@end