Obj-C XML Parser


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



Copy this code and paste it in your HTML
  1. // Define the XML Document
  2. NSXMLDocument* doc = [[NSXMLDocument alloc] initWithXMLString:[NSString stringWithContentsOfFile:@"/folder/with/sample.xml"]];
  3.  
  4. // Create the arrays here
  5. NSMutableArray* objects = [[NSMutableArray alloc] initWithCapacity:10];
  6. NSMutableArray* descriptions = [[NSMutableArray alloc] initWithCapacity:10];
  7.  
  8. NSXMLDocument* doc = [[NSXMLDocument alloc] init...];
  9. NSXMLElement* root = [doc rootElement];
  10. NSArray* objectElements = [root nodesForXPath:@"//object" error:nil];
  11. for(NSXMLElement* xmlElement in objectElements)
  12. [objects addObject:[xmlElement stringValue]];
  13.  
  14. NSArray* descElements = [root nodesForXPath:@"//description" error:nil];
  15. for(NSXMLElement* xmlElement in descElements)
  16. [descriptions addObject:[xmlElement stringValue]];
  17.  
  18. [doc release];
  19. [objects release];
  20. [descriptions release];

URL: http://cocoadev.com/forums/comments.php?DiscussionID=163

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.