+ (NSMutableDictionary*) getXMLNodeInDictionary:(TBXMLElement *)element {
NSMutableDictionary* retDict = [NSMutableDictionary new];
do {
if (element->firstChild) {
if ([retDict valueForKey:[TBXML elementName:element]]==nil) {
[retDict setObject:[self getXMLNodeInDictionary:element->firstChild] forKey:[TBXML elementName:element]];
}else if ([[retDict valueForKey:[TBXML elementName:element]] isKindOfClass:[NSMutableArray class]]) {
[[retDict valueForKey:[TBXML elementName:element]] addObject:[self getXMLNodeInDictionary:element->firstChild]];
}else {
NSMutableArray* arr = [NSMutableArray new];
[arr addObject:[retDict valueForKey:[TBXML elementName:element]]];
[arr addObject:[self getXMLNodeInDictionary:element->firstChild]];
[retDict setObject:[arr autorelease] forKey:[TBXML elementName:element]];
}
}else {
[retDict setObject:[TBXML textForElement:element] forKey:[TBXML elementName:element]];
}
} while ((element = element->nextSibling));
return [retDict autorelease];
}
+ (NSMutableDictionary*)getXMLFileInDictionary:(NSString*)filenameWithFullPath{
NSString* str = [[NSString alloc]initWithContentsOfFile:filenameWithFullPath];
TBXML * tbxml = [TBXML tbxmlWithXMLString:str];
if (!tbxml.rootXMLElement) {
return nil;
}
return [self getXMLNodeInDictionary:tbxml.rootXMLElement];
}
Thanks for your time :)
BR
Ahmed Essam
1 comment:
unfortunatively its not working for the attributes :(
Post a Comment