Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-10-2010, 11:05 AM   #1 (permalink)
Nos
Registered Member
 
Join Date: Aug 2008
Posts: 132
Nos is on a distinguished road
Default How to parse XML files from the Documents Directory of the app ???

Hi everybody,

I don't know if someone has encountered this problem.
I'm trying to parse an xml file from the Documents Directory of my app and it crash. I use NSXMLParser and when i try to parse it, i've the NSXMLParserTagNameMismatchError, i don't know why because i can parse the same xml file when the xml file is in the Bundle.

Here is my code :
NSData *dataTest = (NSData*)[[NSFileManager defaultManager]contentsAtPath:[self DocumentDirectory:@"myFile.xml"]];
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:dataTest];

And the DocumentDirectory function :
-(NSString *)DocumentDirectoryNSString *)relPath
{
NSArray *docPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory, NSUserDomainMask, YES);
NSString *path = [docPaths objectAtIndex: 0];
if (relPath != nil )
path = [path stringByAppendingPathComponent: relPath];
NSLog(@"Path = %@", path);
return path;
}

Best Regards,

NosProduction
Nos is offline   Reply With Quote
Old 08-10-2010, 11:17 AM   #2 (permalink)
Registered Member
 
sundarrif's Avatar
 
Join Date: May 2009
Location: India
Age: 25
Posts: 30
sundarrif is on a distinguished road
Send a message via Skype™ to sundarrif
Default

Try the following code

NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:[self DocumentDirectory:@"myFile.xml"]]];
sundarrif is offline   Reply With Quote
Old 08-10-2010, 11:40 AM   #3 (permalink)
Nos
Registered Member
 
Join Date: Aug 2008
Posts: 132
Nos is on a distinguished road
Default

Thanks for reply.
I already tried your code and it crashed.
I found the error. I test my xml file in the The W3C Markup Validation Service
and my file had some errors.

Sorry...

Best Regards,

NosProduction
Nos is offline   Reply With Quote
Old 08-11-2010, 04:38 AM   #4 (permalink)
Registered Member
 
fousulameen's Avatar
 
Join Date: Jul 2010
Location: chennai
Posts: 41
fousulameen is on a distinguished road
Send a message via Skype™ to fousulameen
Default parsing from document directory....

Quote:
Originally Posted by Nos View Post
Thanks for reply.
I already tried your code and it crashed.
I found the error. I test my xml file in the The W3C Markup Validation Service
and my file had some errors.

Sorry...

Best Regards,

NosProduction

hey try this code.... this may be helpful to u....

NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocum entDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory=[paths objectAtIndex:0];
NSString *writablePath=[documentsDirectory stringByAppendingPathComponent:@"myFile.xml"];
NSURL *xmlURL = [NSURL fileURLWithPath:writablePath isDirectory:NO];

NSXMLParser *firstParse = [[NSXMLParser alloc] initWithContentsOfURL: xmlURL];
[firstParse setDelegate: self];
[firstParse parse];


fousulameen is offline   Reply With Quote
Old 08-11-2010, 04:45 AM   #5 (permalink)
Nos
Registered Member
 
Join Date: Aug 2008
Posts: 132
Nos is on a distinguished road
Default

Thanks for reply.
It works now. The only mistakes were on my xml file.
Sorry

Best Regards,

NosProduction
Nos is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 348
9 members and 339 guests
bignoggins, Chickenrig, firecall, iNet, linkmx, michaelhansen, Objective Zero, PlutoPrime, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,893
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:38 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0