Posted By

mattprice on 12/19/09


Tagged


Versions (?)

Who likes this?

10 people have marked this snippet as a favorite

zingo
tbass134
mracoker
stationstops
avanadra
sb
nsbuckner
im3der
Tintenklecks
ringo380


Obj-C XML Parser


 / Published in: Objective C
 

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

  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];

Report this snippet  

You need to login to post a comment.