From ace8bea34a0908990b7ee57e5f5f2319192998ab Mon Sep 17 00:00:00 2001 From: Yasufumi Muranaka Date: Mon, 20 May 2019 18:47:05 +0900 Subject: [PATCH] Eliminate kXMLReaderTextNodeKey. --- XMLReader.m | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) mode change 100644 => 100755 XMLReader.m diff --git a/XMLReader.m b/XMLReader.m old mode 100644 new mode 100755 index 754c95a..41fbc1a --- a/XMLReader.m +++ b/XMLReader.m @@ -12,9 +12,6 @@ #error "XMLReader requires ARC support." #endif -NSString *const kXMLReaderTextNodeKey = @"text"; -NSString *const kXMLReaderAttributePrefix = @"@"; - @interface XMLReader () @property (nonatomic, strong) NSMutableArray *dictionaryStack; @@ -143,24 +140,28 @@ - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName nam - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { + // Pop the current dict + [self.dictionaryStack removeLastObject]; + // Update the parent dict with text info NSMutableDictionary *dictInProgress = [self.dictionaryStack lastObject]; // Set the text property - if ([self.textInProgress length] > 0) + NSString *trimmedString = [self.textInProgress stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + if (trimmedString.length > 0) { // trim after concatenating - NSString *trimmedString = [self.textInProgress stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; - [dictInProgress setObject:[trimmedString mutableCopy] forKey:kXMLReaderTextNodeKey]; - + NSArray *keys = ((NSMutableDictionary*)dictInProgress[elementName]).allKeys; + if (keys.count) { + [dictInProgress[elementName] setObject:[trimmedString mutableCopy] forKey:elementName]; + } else { + [dictInProgress setObject:[trimmedString mutableCopy] forKey:elementName]; + } // Reset the text self.textInProgress = [[NSMutableString alloc] init]; } - - // Pop the current dict - [self.dictionaryStack removeLastObject]; } - + - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { // Build the text value