I've created an app using xml parser from a tutorial.But this tutorial found to be easy.In this an xml file is parsed from local xml..But if i need to parse an value from xml file say www.xxxxx.com/xxx.xml..how can i modify the code...Guidance please..
- (void) applicationDidFinishLaunching:(UIApplication *)application {
// find "sample.xml" in our bundle resources
NSString *sampleXML = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"xml"];
NSData *data = [NSData dataWithContentsOfFile:sampleXML];
// create a new SMXMLDocument with the contents of sample.xml
NSError *error;
SMXMLDocument *document = [SMXMLDocument documentWithData:data error:&error];
// check for errors
if (error) {
NSLog(@"Error while parsing the document: %@", error);
return;
}
// demonstrate -description of document/element classes
NSLog(@"Document:\n %@", document);
// Pull out the <books> node
SMXMLElement *books = [document.root childNamed:@"books"];
// Look through <books> children of type <book>
for (SMXMLElement *book in [books childrenNamed:@"book"]) {
// demonstrate common cases of extracting XML data
NSString *isbn = [book attributeNamed:@"isbn"]; // XML attribute
NSString *title = [book valueWithPath:@"title"]; // child node value
float price = [[book valueWithPath:@"price"] floatValue]; // child node value (converted)
// show off some KVC magic
NSArray *authors = [[book childNamed:@"authors"].children valueForKey:@"value"];
NSLog(@"Found a book!\n ISBN: %@ \n Title: %@ \n Price: %f \n Authors: %@", isbn, title, price, authors);
}
}
I've tried many tutorials for so many hours and finally i got well from using these code in my app.But i need to import xml file from server...