I am currently trying to parse some xml data into an NSDictionary
. This is the first time I have tried something like this and am a little bit unsure of what I am doing,
First off I am parsing some XML that looks roughly like this -
<Rows>
<Row ID="76" MANF="JARD" ISMANUF="F" ISSER="F"/>
<Row ID="38" MANF ="SANBIN" ISMANUF ="F" ISSER ="T"/>
<Rows>
I am using the NSXMLParser
delegates, so using a NSLog
NSLog(@"attributes: %@", attributeDict);
on parser:didStartElement:namespaceURI:qualifiedName:attributes:
delegate method and my output looks like this.
}
2011-10-11 08:01:15.472 Code[526:207] attributes: {
ISMANUF = F;
ISSER = T;
MANF = smart;
ID = 74;
}
2011-10-11 08:01:15.472 Code[526:207] attributes: {
ISMANUF = F;
ISSER = T;
MANF = "weather guard";
ID = 71;
}
I am now looking to parse this stuff into a NSMutableDictionary
but am not toatly sure on how to go about this... I am looking to do something like this
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
if ([elementName isEqualToString:@"row"]) {
myDic = [[myDic alloc] init];
myDic.isManuf = [attributeDict objectForKey:@"ISMANUF"];
myDic.isSer = [attributeDict valueForKey:@"ISSER"];
myDic.Manf = [attributeDict valueForKey:@"MANF"]
myDic.id = [attributeDict valueForKey:@"ID"]
}
}
My question becomes dose this look right? and then if so how do I declare this mutable dictionary in the header file? and also how to I declared .isManuf .isSer .Manf .id for this NSMutableDictionary