I'm trying to parse a XML File. It worked very well - until today...
Here's how I start to parse the XML:
NSString *link = [[NSString alloc] init];
link = @"link_to_xml_file";
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:link]
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:30.0];
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
And here's how I'm using the received data:
- (void)connection:(NSURLConnection *)theConnection
didReceiveData:(NSData *)incrementalData
{
if (data == nil)
data = [[NSMutableData alloc] init];
[data appendData:incrementalData];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.plist",actual]];
NSError *parseError = nil;
NSDictionary *xmlDictionary = [XMLReader dictionaryForXMLString:[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] error:&parseError];
if (parseError != nil) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:[parseError localizedDescription] delegate:nil cancelButtonTitle:@"Zurück" otherButtonTitles:nil];
[alert show];
[alert release];
} //shows an alertview with NSXMLParserErrorDomain error 5
NSLog(@"String: %@",[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); //returns null
NSLog(@"Dictionary: %@",xmlDictionary); //returns null
NSMutableDictionary *tempDictForAddDate = [[NSMutableDictionary alloc] initWithDictionary:xmlDictionary];
NSDateFormatter *originalDate = [[NSDateFormatter alloc] init];
[originalDate setDateFormat:@"dd.MM.yyyy"];
NSString *today = [originalDate stringFromDate:[NSDate date]];
[tempDictForAddDate setObject:today forKey:@"updated"];
[tempDictForAddDate writeToFile:filePath atomically:YES];
self.contentList = [[tempDictForAddDate objectForKey:@"xmlObject"] objectForKey:@"event"];
[self sortContent];
}
The XML-File works in my browser. And every tag is closed. There aren't any errors but I never get the data of the file.
I hope someone can help.
mavrick3.