【问题标题】:cannot get value when parsing XML in iPhone SDK在 iPhone SDK 中解析 XML 时无法获取值
【发布时间】:2009-07-25 13:56:42
【问题描述】:

我已使用以下代码解析 xml 文件,但无法获取值

 (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 
    attributes:(NSDictionary *)attributeDict {
    
    if([elementName isEqualToString:@"Query"]) {
        //Initialize the array.
        appDelegate.books = [[NSMutableArray alloc] init];
    }
    else if([elementName isEqualToString:@"city"]) {
        
        //Initialize the book.
        aBook = [[Book alloc] init];
        
        //Extract the attribute here.
        aBook.bookID = [attributeDict objectForKey:@"name"];
        
        //NSLog(@"Reading id value :%i", aBook.bookID);
    }
    
    //NSLog(@"Processing Element: %@", elementName);
}
<Query type="cities" status="0" message="success"> 
<city code="AAL" name="Aalborg DK "/> 
<city code="AES" name="Aalesund NO "/> 
<city code="AAR" name="Aarhus DK "/> 
<city code="YXX" name="Abbotsford BC CA "/> 
<city code="ABZ" name="Aberdeen GB "/> 
<city code="ABR" name="Aberdeen SD US "/> 
<city code="AHB" name="Abha SA "/> 
<city code="ABJ" name="Abidjan CI "/> 
<city code="ABI" name="Abilene TX US "/> 
<city code="AUH" name="Abu Dhabi Intl Apt AE "/> 
<city code="ABS" name="Abu Simbel EG "/> 
<city code="ABV" name="Abuja Intl NG "/>

【问题讨论】:

  • xml 格式

标签: iphone


【解决方案1】:

您需要至少 3 个 NSXMLParser 委托才能正确解析 XML - 请在此处查看:http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/XMLParsing/Articles/UsingParser.html 以查看实际说明。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 2011-02-26
    相关资源
    最近更新 更多