Closed Daniate closed 11 years ago
I've not been able to reproduce this problem. Can you provide some sample XML demonstrating this issue?
@nicklockwood here is the sample xml:
<code><request>
<Username>berrylai@suep.com</Username>
<LastUpdateDate>2013-05-07 17:22:52</LastUpdateDate>
<Storename>test</Storename>
<Storetype></Storetype>
<Storedescription></Storedescription>
<Storelogo></Storelogo>
</request></code>
then the dictionary from this xml is: { LastUpdateDate = "2013-05-07"; Storedescription = { "name" = Storedescription; }; Storelogo = { "name" = Storelogo; }; Storename = test; Storetype = { "name" = Storetype; }; Username = "test@test.com"; "name" = request; }
The tag ,Storedescription, Storelogo and Storetype,value is error in the dictionary.It should be Storelogo = "",Storename="",Storetype = "",right?
As I checked the code ,I found that you didn't handle it when the _text length is zero in endtext.
- (void)endText
{
if (_trimWhiteSpace)
{
_text = [[_text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] mutableCopy];
}
if ([_text length])
{
NSMutableDictionary *top = [_stack lastObject];
id existing = top[XMLDictionaryTextKey];
if ([existing isKindOfClass:[NSArray class]])
{
[existing addObject:_text];
}
else if (existing)
{
top[XMLDictionaryTextKey] = [@[existing, _text] mutableCopy];
}
else
{
top[XMLDictionaryTextKey] = _text;
}
}
else
{
// HERE
}
_text = nil;
}
Nick, Really sorry, I was wrong. It was a dictionary instead of an array.
<root> <xxx>1</xxx> <xxx></xxx> <xxx>2</xxx> <root>
it's result is, { "name" = root; root = { "name" = root; }; xxx = ( 1, { "__name" = xxx; }, 2 ); }
After I changed the endText method, it's result is, { "name" = root; "text" = ""; root = { "__name" = root; }; xxx = ( 1, "", 2 ); }
I use version 1.0
This should be fixed in version 1.3 - the behaviour of returning a dictionary for empty nodes was by design, but counterintuitive. I've added a new property "stripEmptyNodes" (on by default) that fixes this.
If parse a tag like
<ref></ref>
,it's content is blank, it will be parsed into an array @[@""].I think, it need to be parsed into an empty string directly.I do a few changes in the endText method.
Best regards.