XMLDictionary icon indicating copy to clipboard operation
XMLDictionary copied to clipboard

XMLString returns wrong result

Open Lamerchun opened this issue 11 years ago • 1 comments

dictionary {
 root: array {
  .... 100 items
 }
}

returns 12...

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];
}
...

Lamerchun avatar Sep 17 '14 14:09 Lamerchun

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];
}

BadChoice avatar Aug 04 '15 14:08 BadChoice