Using DDXML to parse an XML file


/ Published in: Objective C
Save to your folder(s)



Copy this code and paste it in your HTML
  1. NSString *filePath = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"xml"];
  2. NSData *data = [NSData dataWithContentsOfFile:filePath];
  3. if (data) {
  4. NSError *error = nil;
  5. DDXMLDocument* doc = [[DDXMLDocument alloc]initWithData:data options:0 error:&error];
  6.  
  7. if(error != nil){
  8. NSLog(@"DDXMLDocument create failed! Error - %@", [error localizedDescription]);
  9. return;
  10. }
  11. NSArray* results = [listingsXMLDoc nodesForXPath:@"//node" error:&error];
  12. NSLog(@"parsed: %i", [results count]);
  13. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.