Skip to content

Commit ace8bea

Browse files
Eliminate kXMLReaderTextNodeKey.
1 parent be2246c commit ace8bea

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

XMLReader.m

100644100755
Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
#error "XMLReader requires ARC support."
1313
#endif
1414

15-
NSString *const kXMLReaderTextNodeKey = @"text";
16-
NSString *const kXMLReaderAttributePrefix = @"@";
17-
1815
@interface XMLReader ()
1916

2017
@property (nonatomic, strong) NSMutableArray *dictionaryStack;
@@ -143,24 +140,28 @@ - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName nam
143140

144141
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
145142
{
143+
// Pop the current dict
144+
[self.dictionaryStack removeLastObject];
145+
146146
// Update the parent dict with text info
147147
NSMutableDictionary *dictInProgress = [self.dictionaryStack lastObject];
148148

149149
// Set the text property
150-
if ([self.textInProgress length] > 0)
150+
NSString *trimmedString = [self.textInProgress stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
151+
if (trimmedString.length > 0)
151152
{
152153
// 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+
}
156160
// Reset the text
157161
self.textInProgress = [[NSMutableString alloc] init];
158162
}
159-
160-
// Pop the current dict
161-
[self.dictionaryStack removeLastObject];
162163
}
163-
164+
164165
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
165166
{
166167
// Build the text value

0 commit comments

Comments
 (0)