开发者

how to pass local path to NSXMLParser

how to pass local path to NSXMLParser

like this

NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:storePath];

where storepath is a local path like this:

/var/mobile/Applications/56EEB906-2B73-493C-9BE7-2732440CDB69/Documents/xml1.php

and my code is like this:

//NSURL *urla = [[NSURL alloc] initWithString:storePath];
NSURL *urla = [[[NSURL alloc] init] fileURLWithPath:storePath];

//NSData *dataa = [NSData dataWithContentsOfURL:urla];

NSLog(@"urls ois %@",u开发者_如何学Gorla);

help me why i am getting null value


Hey THis all some what not fair.

i suggest this, very simple

        NSString *path=@"/Users/farshore/Desktop/prasanna/XMLParsing/Books-6.xml";  //this is ur path of xml file


        NSURL *url = [[NSURL alloc] initFileURLWithPath:path];


Try this one:

NSArray *paths = NSSearchPathForDirectoriesInDomains(
                     NSDocumentDirectory,
                     NSUserDomainMask, YES
                 );
NSString *documentsDirectory = [paths objectAtIndex:0];
NSURL *urla = [NSURL fileURLWithPath:[documentsDirectory
                         stringByAppendingString:@"/xml1.php"]];

More details at iPhone Application Programming Guide: Getting Paths to Application Directories.

Update: There's a common misunderstanding what stringByTrimmingCharactersInSet. It does not replace all whitespace in the string, it only removes leading and trailing whitespace.

If you want to get rid of the spaces, you need to replace them yourself by using something like stringByReplacingCharactersInRange:withString:.

However:

  • I am not sure what you would replace those strings with to get a valid path. As far as I know, on the simulator the path to the application's Documents folder actually has spaces in it (which accidentally is called out in the document I linked).
  • I am not sure why would the spaces bother you. That string is a valid path (as long as you actually have created the <app>/Documents/xml1.php file, of course); and according to NSXMLParser documentation, initWithContentsOfUrl accepts any fully qualified URL with scheme supported by NSURL, and file:// is supported scheme.

If there's a particular error the NSXMLParser is returning, add it to your question (or ask another one), so we can help you with the actual problem.


My guess would be because you're reading the PHP file directly instead of passing it through PHP so the output isn't XML.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜