I have a class which parse an XML feed. In that class I have to following method:
-(id)loadXMLByURL:(NSString *)urlString name:(NSString*)name{
NSString *urls = [[NSString alloc]initWithFormat:@"%@%@" , urlString, name];
NSLog(@"STRING URL: %@" , urls);
NSURL *url = [NSURL URLWithString:urls];
NSLog(@"%@" , url);
parser = [[NSXMLParser alloc]initWithContentsOfURL:url];
parser.delegate = self;
BOOL success = [parser parse];
if (success) {
NSLog(@"No error");
}else{
NSLog(@"Error: %@" , parser.parserError);
}
return self;
}
The first NSLog is the correct url, however the NSURL comes out as (null)
Here’s where I call the method:
//f is an object where I store the value of name from another feed, which I have to use as a parameter in the url for this feed
NSString *name = f.name;
myParser = [[MyParser alloc]loadXMLByURL:@"http://myurl.com/names.asp?name=" name:name];
If I NSLog name here, it shows the right value.
Anyone have any idea why the NSURL comes out as (null)?
You’ll want to escape
name.Add a category on
NSStringand then call[name urlEncodedString]. e.g.: