我用来XSXMLparser
从网站解析一些 XML,然后通过以下方式在表中显示键:
[myDictionary allKeys]objectAtIndex:indexPath.row;
然后在选择时创建表的一个新实例并通过属性设置重要变量:
tableScreen *tableScreenNew = [[tableScreen alloc]init];
tableScreenNew.currentLevel = 1;
tableScreenNew.numberOfRows = counter;
tableScreenNew.parsedData = parsedData;
[self.navigationController pushViewController:tableScreenNew animated:YES];
这将使用我需要的数据推送新表,并且cellForRow:
我只有一个 if:
if(currentLevel == 0)
{
}
else if(currentLevel == 1)
{
}
else
{
NSLog(@"I Messed up");
}
并在 cellForRow 中为您的情况分配一个临时字典:
NSDictionary *tempDictionary = [NSDictionary dictionaryWithDictionary:[originalParsedData valueForKey:dateKeyNameFromLastTable]];
编辑:解析代码
NSData *myData = [xmlToParse dataUsingEncoding:NSUTF16StringEncoding];
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:myData];
[parser setDelegate:self];
if([parser parse])
{
NSLog(@"Success");
NSLog(@"****************************** Finished Dictionary ******************************");
for(int i = 0;i < [parsedData count];i++)
{
NSLog(@"%d:%@",i,[parsedData objectAtIndex:i]);
}
NSLog(@"*********************************************************************************");
}
else
{
NSLog(@"Epic Fail");
NSLog(@"%@",[parser parserError]);
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict
{
NSLog(@"Processing Element: %@", elementName);
NSLog(@"Processing Attributes: %@", attributeDict);
//Here you would start adding the key/Dicts to a NSMutableDictionary which you would use to populate tables
[myNSMutableDictionary addObject:attributeDict forKey:elementName];
}