objective c - iOS cannot parse KML / XML downloaded from server -


a kml file include in project parses correctly whereas same file downloaded server not?!

i modified apple's kml parsing example parse kml file. if add kml file directly xcode project parses correctly , displays it's polylines, annotations, etc. on map expected. if download same kml file server, save disk , attempt parse it, parsing not work. i.e. parser not find elements parse in file nothing displayed on map!

firstly have verified file downloads , saves disk correctly. checked simulator's data (simpholders handy tool this) file , compare original 1 in case of corruption, no problem there, downloads , saves correctly, no corruption.

i next checked url file pass kml parser ensure correct , fine. used nsfilemanager fileexistsatpath determine this, kml file @ path provide parser.

in map view controller's viewdidload method download file server , pass parser.

- (void)viewdidload {     [super viewdidload];      [[kmldownloader sharedkmldownloader] downloadfilefrom:@"http://www.myserver.com/file.kml" isasyncdownload:no];     nsurl *kmlurl = [[kmldownloader sharedkmldownloader] urlforkmlfile];      if (kmlurl)     {         kmlparser = [[kmlparser alloc] initwithurl:kmlurl];         [kmlparser parsekml];     }        // add of mkoverlay objects parsed kml file map.     nsarray *overlays = [kmlparser overlays];     [map addoverlays:overlays];      // add of mkannotation objects parsed kml file map.     nsarray *annotations = [kmlparser points];     [map addannotations:annotations];      // positioning code of view port here } 

kmldownloader reference can found gist here. sorry formatting messing include inline, relatively small file though.

any ideas why may happening? many thanks.

ok found issue. how accessing file once downloaded. once saved disk send it's url parser. problem was using incorrect nsurl method, using:

nsurl *fileurl = [nsurl urlwithstring:[self pathforfile:self.pathtokmlfileondisk]]; 

whereas should have been using:

nsurl *fileurl = [[nsurl alloc] initfileurlwithpath:self.pathtokmlfileondisk]; 

both same url second 1 includes "file:///" prefix. once changed parser parse expected.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -