The whole snippet is:
NSDictionary *DictionaryForNode(xmlNodePtr currentNode, NSMutableDictionary *parentResult,BOOL parentContent)
{
@autoreleasepool {
NSMutableDictionary *resultForNode = [@{} mutableCopy];
if (currentNode->name) {
NSString *currentNodeContent = [NSString stringWithCString:(const char *)currentNode->name
encoding:NSUTF8StringEncoding];
resultForNode[@"nodeName"] = currentNodeContent;
}
xmlChar *nodeContent = xmlNodeGetContent(currentNode);
if (nodeContent != NULL) {
NSString *currentNodeContent = [NSString stringWithCString:(const char *)nodeContent
encoding:NSUTF8StringEncoding];
if ([resultForNode[@"nodeName"] isEqual:@"text"] && parentResult) {
if (parentContent) {
NSCharacterSet *charactersToTrim = [NSCharacterSet whitespaceAndNewlineCharacterSet];
parentResult[@"nodeContent"] = [currentNodeContent stringByTrimmingCharactersInSet:charactersToTrim];
xmlFree(nodeContent);
return nil;
}
if (currentNodeContent != nil) {
resultForNode[@"nodeContent"] = currentNodeContent;
}
xmlFree(nodeContent);
return resultForNode;
} else {
resultForNode[@"nodeContent"] = currentNodeContent;
}
xmlFree(nodeContent);
}
xmlAttr *attribute = currentNode->properties;
if (attribute) {
NSMutableArray *attributeArray = [@[] mutableCopy];
while (attribute) {
@autoreleasepool
{
NSMutableDictionary *attributeDictionary = [@{} mutableCopy];
NSString *attributeName = [NSString stringWithCString:(const char *)attribute->name
encoding:NSUTF8StringEncoding];
if (attributeName) {
attributeDictionary[@"attributeName"] = attributeName;
}
if (attribute->children) {
NSDictionary *childDictionary = DictionaryForNode(attribute->children, attributeDictionary, true);
if (childDictionary) {
attributeDictionary[@"attributeContent"] = childDictionary;
}
}
if ([attributeDictionary count] > 0) {
[attributeArray addObject:attributeDictionary];
}
attribute = attribute->next;
attributeDictionary = nil;
}
}
if ([attributeArray count] > 0) {
resultForNode[@"nodeAttributeArray"] = attributeArray;
}
attributeArray = nil;
}
xmlNodePtr childNode = currentNode->children;
if (childNode) {
NSMutableArray *childContentArray = [@[] mutableCopy];
while (childNode) {
NSDictionary *childDictionary = DictionaryForNode(childNode, resultForNode,false);
if (childDictionary) {
[childContentArray addObject:childDictionary];
}
childNode = childNode->next;
}
if ([childContentArray count] > 0) {
resultForNode[@"nodeChildArray"] = childContentArray;
}
childContentArray = nil;
}
xmlBufferPtr buffer = xmlBufferCreate();
xmlNodeDump(buffer, currentNode->doc, currentNode, 0, 0);
NSString *rawContent = [NSString stringWithCString:(const char *)buffer->content encoding:NSUTF8StringEncoding];
if (rawContent != nil) {
resultForNode[@"raw"] = rawContent;
}
xmlBufferFree(buffer);
return resultForNode;
}
}
And how do I debug memory leaks according to this screenshot? Thanks!