NSDictionary
的NSMutableArray
對於您的內存數據結構似乎是一種合理的方法。
你基本上有一個系列,通過你的XML文件構建該數組爲NSXMLParser
運行的回調:
- (void) parseXML:(NSString *) filename {
NSURL *xmlURL = [NSURL fileURLWithPath:filename];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
[xmlParser setDelegate:self];
[xmlParser parse];
// Check for errors.
NSError *errorCode = [xmlParser parserError];
if (errorCode) {
// handle error here
NSLog(@"%@", [errorCode localizedDescription]);
}
[xmlParser release];
}
而且你的主要代表人物:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
{
// If certain elements are found initialize the object
if ([elementName isEqualToString:"@file"]) {
NSMutableDictionary *currentFile = [[NSMutableDictionary alloc] init];
// Look through the attributes add stuff to your dictionary
// Add it to your array.
}
}
由於所有數據返回屬性,你可以這樣做。否則,當didEndElement
委託中的文件標籤出現時,您需要存儲文件並將其構建(foundCharacters
委派),最後將其添加到陣列中。
你會還想在完成解析後在你的'UITableView'上調用'reloadData'。 – 2010-01-05 22:32:19
感謝您的建議 – PirosB3 2010-07-29 17:26:02