Skip to content
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

After parsing is complete when you set the Text property value is a special error #15

Open
LeeYZ opened this issue Jan 17, 2016 · 0 comments

Comments

@LeeYZ
Copy link

LeeYZ commented Jan 17, 2016

I have an XML document, in the following format:

<?xml version="1.0" encoding="utf-8"?>
<vcread>
  <bg_img id="32" title="背景(7)" x="0" y="0" width="320" height="480" src="333_07.jpg" tag="" seq="0" />
  <item>
    <text id="33" title="文本" x="19" y="309" width="284" height="166" type="char" content="ContentText"/>
  </item>
</vcread>

Your code:

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
    // Update the parent dict with text info
    NSMutableDictionary *dictInProgress = [self.dictionaryStack lastObject];

    // Set the text property
    if ([self.textInProgress length] > 0)
    {
        // trim after concatenating
        NSString *trimmedString = [self.textInProgress stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
        [dictInProgress setObject:[trimmedString mutableCopy] forKey:kXMLReaderTextNodeKey];

        // Reset the text
        self.textInProgress = [[NSMutableString alloc] init];
    }

    // Pop the current dict
    [self.dictionaryStack removeLastObject];
}

When the analysis is completed, item-> text has been nil, I debugged the code, find item-> text after the first, was reset to nil, so I modified the code and commit, please test,thank you

LeeYZ added a commit to LeeYZ/XMLReader that referenced this issue Jan 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant