Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>mmm.... maybe your confusion is about the delegate pattern.</p> <p>A delegate is simply an object that receives messages in place of another object. Think of it as a callback mechanism.</p> <p>My suggestion is that you create a separate class for parsing XML files, like this:</p> <pre><code>@interface MyXMLParser : NSObject&lt;NSXMLParserDelegate&gt; </code></pre> <p>This class has a NSMutableArray of results and a parse method.</p> <p>The parse method will look like this:</p> <pre><code>-(void) parse:(NSString *)xmlFilePath { self.results = [[NSMutableArray alloc] init]; NSURL* xmlURL = [NSURL fileURLWithPath:xmlFilePath]; NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL]; parser.delegate = self; [parser parse]; [parser release]; } </code></pre> <p>In this class you also need to implement the delegate methods. These methods will get called inside the [parser parse] call, once for each element that is found in the xml file:</p> <pre><code>- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *) qualifiedName attributes:(NSDictionary *)attributeDict - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string - (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError </code></pre> <p>Inside these methods you need to "understand" the elements you get and store them in the results array.</p> <p>You use this parser like this</p> <pre><code>MyXMLParser* parser = [[MyXmlParser alloc] init]; [parser parse:@"myfile.xml"] NSLog(@"%@", parser.results); [parser release]; </code></pre> <p>Hope it helps.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload