XMLDictionary
XMLDictionary copied to clipboard
XMLString returns wrong result
dictionary {
root: array {
.... 100 items
}
}
returns
in XMLStringForNode if node is an array, subcalls of XMLStringForNode on each array element should be called with nodeName:nil.
if ([node isKindOfClass:[NSArray class]])
{
NSMutableArray *nodes = [NSMutableArray arrayWithCapacity:[node count]];
for (id individualNode in node)
{
[nodes addObject:[self XMLStringForNode:individualNode withNodeName:nil]];
}
return [nodes componentsJoinedByString:@"\n"];
}
...
and if nodeName is nil. result has to be without nodeName around.
if(nodeName)
{
return [NSString stringWithFormat:@"<%1$@%2$@>%3$@</%1$@>", nodeName, attributeString, innerXML];
}
else
{
return [NSString stringWithFormat:@"%@", innerXML];
}
...
I believe the array should be included inside a tag, so do something like this:
if ([node isKindOfClass:[NSArray class]])
{
NSMutableArray *nodes = [NSMutableArray arrayWithCapacity:[node count]];
for (id individualNode in node)
{
[nodes addObject:[self XMLStringForNode:individualNode withNodeName:nil]];
}
return [NSString stringWithFormat:@"<%@>%@</%@>",nodeName,[nodes componentsJoinedByString:@"\n"],nodeName];
}