2

I am developing an application. In that I am getting 500 to 600 questions via xml. But if I parse the total file at one time it takes a lot of time.

So I want to parse the xml file part by part to save the time duration.That means first I parse the xml file for first three questions and after showing those three , I can do the parsing for next three ones and so on.

But how can I stop the parsing after getting the three questions ?

If anybody knows any other approach to do the parsing fast then please tell me. Btw I am using TBXML for parsing.

IronManGill
  • 7,222
  • 2
  • 31
  • 52
Naresh Venkat
  • 163
  • 2
  • 9

1 Answers1

0

Try this. I hope it'll help you:

-(void) loadXML:(NSString *)urlStr
{
    NSData  *data   = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:urlString]];
    parser          = [[NSXMLParser alloc] initWithData:data];
    parser.delegate = self;
    [parser parse];
}

/****
e.g.
<name>Romit</name>
**/
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
    // method to make operation when element stated. <name>
}

- (void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    // you get all data in this delegate method. from string variable.
    // name value
}

- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
   // make operation when element finished.
  //</name>
}
Romit M.
  • 898
  • 11
  • 28