13
13
}
14
14
15
15
@implementation SMXMLElement
16
- @synthesize document, parent, name, value, children, attributes;
17
16
18
- - (id )initWithDocument : (SMXMLDocument *)aDocument {
17
+ - (id )initWithDocument : (SMXMLDocument *)document {
19
18
self = [super init ];
20
19
if (self)
21
- self.document = aDocument ;
20
+ self.document = document ;
22
21
return self;
23
22
}
24
23
25
24
- (NSString *)descriptionWithIndent : (NSString *)indent truncatedValues : (BOOL )truncated {
26
25
27
26
NSMutableString *s = [NSMutableString string ];
28
- [s appendFormat: @" %@ <%@ " , indent, name];
27
+ [s appendFormat: @" %@ <%@ " , indent, self . name];
29
28
30
- for (NSString *attribute in attributes)
31
- [s appendFormat: @" %@ =\" %@ \" " , attribute, [attributes objectForKey: attribute]];
29
+ for (NSString *attribute in self. attributes )
30
+ [s appendFormat: @" %@ =\" %@ \" " , attribute, [self . attributes objectForKey: attribute]];
32
31
33
- NSString *valueOrTrimmed = [value stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet ]];
32
+ NSString *valueOrTrimmed = [self . value stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet ]];
34
33
35
34
if (truncated && valueOrTrimmed.length > 25 )
36
35
valueOrTrimmed = [NSString stringWithFormat: @" %@ …" , [valueOrTrimmed substringToIndex: 25 ]];
37
36
38
- if (children.count ) {
37
+ if (self. children .count ) {
39
38
[s appendString: @" >\n " ];
40
39
41
40
NSString *childIndent = [indent stringByAppendingString: @" " ];
42
41
43
42
if (valueOrTrimmed.length )
44
43
[s appendFormat: @" %@%@ \n " , childIndent, valueOrTrimmed];
45
44
46
- for (SMXMLElement *child in children)
45
+ for (SMXMLElement *child in self. children )
47
46
[s appendFormat: @" %@ \n " , [child descriptionWithIndent: childIndent truncatedValues: truncated]];
48
47
49
- [s appendFormat: @" %@ </%@ >" , indent, name];
48
+ [s appendFormat: @" %@ </%@ >" , indent, self . name];
50
49
}
51
50
else if (valueOrTrimmed.length ) {
52
- [s appendFormat: @" >%@ </%@ >" , valueOrTrimmed, name];
51
+ [s appendFormat: @" >%@ </%@ >" , valueOrTrimmed, self . name];
53
52
}
54
53
else [s appendString: @" />" ];
55
54
@@ -64,8 +63,8 @@ - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
64
63
65
64
if (!string) return ;
66
65
67
- if (value)
68
- [(NSMutableString *)value appendString: string];
66
+ if (self. value )
67
+ [(NSMutableString *)self . value appendString: string];
69
68
else
70
69
self.value = [NSMutableString stringWithString: string];
71
70
}
@@ -76,46 +75,46 @@ - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName nam
76
75
child.name = elementName;
77
76
child.attributes = attributeDict;
78
77
79
- if (children)
80
- [(NSMutableArray *)children addObject: child];
78
+ if (self. children )
79
+ [(NSMutableArray *)self . children addObject: child];
81
80
else
82
81
self.children = [NSMutableArray arrayWithObject: child];
83
82
84
83
[parser setDelegate: child];
85
84
}
86
85
87
86
- (void )parser : (NSXMLParser *)parser didEndElement : (NSString *)elementName namespaceURI : (NSString *)namespaceURI qualifiedName : (NSString *)qName {
88
- [parser setDelegate: parent];
87
+ [parser setDelegate: self . parent];
89
88
}
90
89
91
90
- (void )parser : (NSXMLParser *)parser parseErrorOccurred : (NSError *)parseError {
92
91
self.document .error = SMXMLDocumentError (parser, parseError);
93
92
}
94
93
95
94
- (SMXMLElement *)childNamed : (NSString *)nodeName {
96
- for (SMXMLElement *child in children)
95
+ for (SMXMLElement *child in self. children )
97
96
if ([child.name isEqual: nodeName])
98
97
return child;
99
98
return nil ;
100
99
}
101
100
102
101
- (NSArray *)childrenNamed : (NSString *)nodeName {
103
102
NSMutableArray *array = [NSMutableArray array ];
104
- for (SMXMLElement *child in children)
103
+ for (SMXMLElement *child in self. children )
105
104
if ([child.name isEqual: nodeName])
106
105
[array addObject: child];
107
106
return [array copy ];
108
107
}
109
108
110
109
- (SMXMLElement *)childWithAttribute : (NSString *)attributeName value : (NSString *)attributeValue {
111
- for (SMXMLElement *child in children)
110
+ for (SMXMLElement *child in self. children )
112
111
if ([[child attributeNamed: attributeName] isEqual: attributeValue])
113
112
return child;
114
113
return nil ;
115
114
}
116
115
117
116
- (NSString *)attributeNamed : (NSString *)attributeName {
118
- return [attributes objectForKey: attributeName];
117
+ return [self . attributes objectForKey: attributeName];
119
118
}
120
119
121
120
- (SMXMLElement *)descendantWithPath : (NSString *)path {
@@ -132,13 +131,12 @@ - (NSString *)valueWithPath:(NSString *)path {
132
131
}
133
132
134
133
135
- - (SMXMLElement *)firstChild { return [children count ] > 0 ? [children objectAtIndex: 0 ] : nil ; }
136
- - (SMXMLElement *)lastChild { return [children lastObject ]; }
134
+ - (SMXMLElement *)firstChild { return [self . children count ] > 0 ? [self . children objectAtIndex: 0 ] : nil ; }
135
+ - (SMXMLElement *)lastChild { return [self . children lastObject ]; }
137
136
138
137
@end
139
138
140
139
@implementation SMXMLDocument
141
- @synthesize root, error;
142
140
143
141
- (id )initWithData : (NSData *)data error : (NSError **)outError {
144
142
self = [super init ];
@@ -168,21 +166,21 @@ + (SMXMLDocument *)documentWithData:(NSData *)data error:(NSError **)outError {
168
166
- (void )parser : (NSXMLParser *)parser didStartElement : (NSString *)elementName namespaceURI : (NSString *)namespaceURI qualifiedName : (NSString *)qName attributes : (NSDictionary *)attributeDict {
169
167
170
168
self.root = [[SMXMLElement alloc ] initWithDocument: self ];
171
- root.name = elementName;
172
- root.attributes = attributeDict;
173
- [parser setDelegate: root];
169
+ self. root .name = elementName;
170
+ self. root .attributes = attributeDict;
171
+ [parser setDelegate: self . root];
174
172
}
175
173
176
174
- (void )parser : (NSXMLParser *)parser parseErrorOccurred : (NSError *)parseError {
177
175
self.error = SMXMLDocumentError (parser, parseError);
178
176
}
179
177
180
178
- (NSString *)description {
181
- return root.description ;
179
+ return self. root .description ;
182
180
}
183
181
184
182
- (NSString *)fullDescription {
185
- return [root descriptionWithIndent: @" " truncatedValues: NO ];
183
+ return [self . root descriptionWithIndent: @" " truncatedValues: NO ];
186
184
}
187
185
188
186
@end
0 commit comments