daveomcd
daveomcd

Reputation: 6555

iPhone: How do I "cancel" my xmlparser from parsing in objective c?

In my

- (void)parser:(NSXMLParser *)parser
        didStartElement:(NSString *)elementName
           namespaceURI:(NSString *)namespaceURI
          qualifiedName:(NSString *)qualifiedName
             attributes:(NSDictionary *)attributeDict {
          // ...
}

I check to see if one of my XML attributes is equal to a value I store in my plist. If it's not then I want it to execute normally and get the latest information. If it is the same value though I don't want to waste the processing time of getting all the data again. So if I have code like below how can I terminate the parsing process if the values are the same?

if (lastUpdated == [attributeDict valueForKey:@"last_updated"]) {
     // Terminate the xml parsing because data is up to date
}

Upvotes: 0

Views: 169

Answers (3)

Plamen Terziev
Plamen Terziev

Reputation: 116

Just note that there is a bug in iOS 6.0 and abortParsing will cancel the parser but will not call parser:parseErrorOccurred and will not set 'parserError'.

Upvotes: 1

jrturton
jrturton

Reputation: 119242

You can use [parser abortParsing] but note that this is intended for XML errors rather than "I don't want this data" situations and can cause your parser:parseErrorOcurred: method to be called a couple of times, in my experience.

Upvotes: 3

Apurv
Apurv

Reputation: 17186

Call [parser abortParsing] to cancel parsing from current point.

Upvotes: 1

Related Questions