Return to Snippet

Revision: 21742
at December 19, 2009 17:12 by mattprice


Updated Code
// Define the XML Document
NSXMLDocument* doc = [[NSXMLDocument alloc] initWithXMLString:[NSString stringWithContentsOfFile:@"/folder/with/sample.xml"]];

// Create the arrays here
NSMutableArray* objects = [[NSMutableArray alloc] initWithCapacity:10];
NSMutableArray* descriptions = [[NSMutableArray alloc] initWithCapacity:10];

NSXMLDocument* doc = [[NSXMLDocument alloc] init...];
NSXMLElement* root  = [doc rootElement];
NSArray* objectElements = [root nodesForXPath:@"//object" error:nil];
for(NSXMLElement* xmlElement in objectElements)
    [objects addObject:[xmlElement stringValue]];

NSArray* descElements = [root nodesForXPath:@"//description" error:nil];
for(NSXMLElement* xmlElement in descElements)
    [descriptions addObject:[xmlElement stringValue]];

[doc release];
[objects release];
[descriptions release];

Revision: 21741
at December 19, 2009 17:11 by mattprice


Updated Code
// Create the arrays here
NSMutableArray* objects = [[NSMutableArray alloc] initWithCapacity:10];
NSMutableArray* descriptions = [[NSMutableArray alloc] initWithCapacity:10];

NSXMLDocument* doc = [[NSXMLDocument alloc] init...];
NSXMLElement* root  = [doc rootElement];
NSArray* objectElements = [root nodesForXPath:@"//object" error:nil];
for(NSXMLElement* xmlElement in objectElements)
    [objects addObject:[xmlElement stringValue]];

NSArray* descElements = [root nodesForXPath:@"//description" error:nil];
for(NSXMLElement* xmlElement in descElements)
    [descriptions addObject:[xmlElement stringValue]];

[doc release];
[objects release];
[descriptions release];

Revision: 21740
at December 19, 2009 16:38 by mattprice


Initial Code
// Create the arrays here
NSMutableArray* objects = [[NSMutableArray alloc] initWithCapacity:10];
NSMutableArray* descriptions = [[NSMutableArray alloc] initWithCapacity:10];

NSXMLDocument* doc = [[NSXMLDocument alloc] init...];
NSXMLElement* root  = [doc rootElement];
NSArray* objectElements = [root nodesForXpath:@"//object" error:nil];
for(NSXMLElement* xmlElement in objectElements)
    [objects addObject:[xmlElement stringValue]];

NSArray* descElements = [root nodesForXPath:@"//description" error:nil];
for(NSXMLElement* xmlElement in descElements)
    [descriptions addObject:[xmlElement stringValue]];

[doc release];
[objects release];
[descriptions release];

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

Initial Description

                                

Initial Title
Obj-C XML Parser

Initial Tags

                                

Initial Language
Objective C