|
12 | 12 | #error "XMLReader requires ARC support."
|
13 | 13 | #endif
|
14 | 14 |
|
15 |
| -NSString *const kXMLReaderTextNodeKey = @"text"; |
16 |
| -NSString *const kXMLReaderAttributePrefix = @"@"; |
17 |
| - |
18 | 15 | @interface XMLReader ()
|
19 | 16 |
|
20 | 17 | @property (nonatomic, strong) NSMutableArray *dictionaryStack;
|
@@ -143,24 +140,28 @@ - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName nam
|
143 | 140 |
|
144 | 141 | - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
|
145 | 142 | {
|
| 143 | + // Pop the current dict |
| 144 | + [self.dictionaryStack removeLastObject]; |
| 145 | + |
146 | 146 | // Update the parent dict with text info
|
147 | 147 | NSMutableDictionary *dictInProgress = [self.dictionaryStack lastObject];
|
148 | 148 |
|
149 | 149 | // Set the text property
|
150 |
| - if ([self.textInProgress length] > 0) |
| 150 | + NSString *trimmedString = [self.textInProgress stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; |
| 151 | + if (trimmedString.length > 0) |
151 | 152 | {
|
152 | 153 | // trim after concatenating
|
153 |
| - NSString *trimmedString = [self.textInProgress stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; |
154 |
| - [dictInProgress setObject:[trimmedString mutableCopy] forKey:kXMLReaderTextNodeKey]; |
155 |
| - |
| 154 | + NSArray *keys = ((NSMutableDictionary*)dictInProgress[elementName]).allKeys; |
| 155 | + if (keys.count) { |
| 156 | + [dictInProgress[elementName] setObject:[trimmedString mutableCopy] forKey:elementName]; |
| 157 | + } else { |
| 158 | + [dictInProgress setObject:[trimmedString mutableCopy] forKey:elementName]; |
| 159 | + } |
156 | 160 | // Reset the text
|
157 | 161 | self.textInProgress = [[NSMutableString alloc] init];
|
158 | 162 | }
|
159 |
| - |
160 |
| - // Pop the current dict |
161 |
| - [self.dictionaryStack removeLastObject]; |
162 | 163 | }
|
163 |
| - |
| 164 | + |
164 | 165 | - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
|
165 | 166 | {
|
166 | 167 | // Build the text value
|
|
0 commit comments