Skip to content

Eliminate kXMLReaderTextNodeKey. #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions XMLReader.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
#error "XMLReader requires ARC support."
#endif

NSString *const kXMLReaderTextNodeKey = @"text";
NSString *const kXMLReaderAttributePrefix = @"@";

@interface XMLReader ()

@property (nonatomic, strong) NSMutableArray *dictionaryStack;
Expand Down Expand Up @@ -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
Expand Down