Two little things to consider:
You should definitely read into the Objective-C / Cocoa documentation.
Otherwise you will never be able to program something yourself.
In the end this will save you lots of time struggling with problems like these.
The things you ask are just the very basics of programming.
(Besides the XML part)
You should never ask people to write complete applications.
People on Stack Overflow are more then willing to help with specific problems,
but they do not work for you.
That being said, here my actual answer:
The XML code you provided contains a syntax error:
The second <Description> should be </Description>
For my example code below I used the following XML file:
<?xml version="1.0" ?>
<Report>
<Date>20110311</Date>
<Title>The Title</Title>
<Description>Description sample</Description>
</Report>
This quickly written example does everything you need.
Create a new application with XCode and open the .....AppDelegate.m file.
Simply paste the Objective-C code mentioned below within the following function:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Paste Here
}
Next click 'Click build and Run'.
Select your file within the NSOpenPanel and click the open-button.
Now you should see a simple dialog with the results.
Hopefully this helps you understand how to parse the XML file.
I can imagine 4 days of struggling must be unpleasant :)
The Objective-C sample code:
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
NSArray *fileTypes = [NSArray arrayWithObjects:@"xml",nil];
NSInteger result = [openPanel runModalForDirectory:NSHomeDirectory() file:nil types:fileTypes ];
if(result == NSOKButton){
NSString * input = [openPanel filename];
NSXMLDocument* doc = [[NSXMLDocument alloc] initWithContentsOfURL: [NSURL fileURLWithPath:input] options:0 error:NULL];
NSMutableArray* dates = [[NSMutableArray alloc] initWithCapacity:10];
NSMutableArray* titles = [[NSMutableArray alloc] initWithCapacity:10];
NSMutableArray* descriptions = [[NSMutableArray alloc] initWithCapacity:10];
NSXMLElement* root = [doc rootElement];
NSArray* dateArray = [root nodesForXPath:@"//Date" error:nil];
for(NSXMLElement* xmlElement in dateArray)
[dates addObject:[xmlElement stringValue]];
NSArray* titleArray = [root nodesForXPath:@"//Title" error:nil];
for(NSXMLElement* xmlElement in titleArray)
[titles addObject:[xmlElement stringValue]];
NSArray* descriptionArray = [root nodesForXPath:@"//Description" error:nil];
for(NSXMLElement* xmlElement in descriptionArray)
[descriptions addObject:[xmlElement stringValue]];
NSString * date = [dates objectAtIndex:0];
NSString * title = [titles objectAtIndex:0];
NSString * description = [descriptions objectAtIndex:0];
NSString *output = [NSString stringWithFormat:@"Date: %@\nTitle: %@\nDescription: %@", date, title, description];
NSRunAlertPanel( @"Result", output, @"OK", nil, nil );
[doc release];
[dates release];
[titles release];
[descriptions release];
}
Here some additional information:
http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/XMLParsing/Articles/UsingParser.html