iPhone XMLParser help

后端 未结 4 929
慢半拍i
慢半拍i 2020-12-20 09:19

I am needing to parse an XML file for my app and I dont have any clue how to do it. I went through one XMLParser tutorial, and it worked fine but the XML file in the tutoria

4条回答
  •  太阳男子
    2020-12-20 09:45

    I suggest you to read the Event-Driven XML Programming Guide for Cocoa. In your specific case, what you need to do is:

    • In the parser:didStartElement: check for the element name: "airport_name", initialize a new array to store all the record elements (or you can define your own data structure to store the record element), a dictionary to store all element in the record, one string variable to store the current text
    • In the parser:foundCharacters: append the string to the current text
    • In the parser:didEndElement: save the dictionary to the array, release the array, save the results.

    UPDATED

    - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
    
        if ( [elementName isEqualToString:@"airport_name"]) {
    
            if (!airports)
                airports = [[NSMutableArray alloc] init];
            NSString *str_icao_ident = [attributeDict objectForKey:@"icao_ident"];
            //do something
            return;
        // ... continued ...
    }}
    

提交回复
热议问题