のNSMutableArrayは、NSDictionaryメモリ内のデータ構造にとって合理的なアプローチのようです。
NSXMLParser基本的に、XMLファイルを実行するときにその配列を構築する一連のコールバックがあります。
- (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.
}
}
すべてのデータが属性で返されるため、この方法で行うことができます。それ以外の場合は、ファイルを保存してビルドし(foundCharactersデリゲート)、ファイルのタグがデリゲートで発生したときに最終的に配列に追加する必要がありますdidEndElement。