Skip to content

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

Open
@LeeYZ

Description

@LeeYZ

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions