NSURL doesn't like get variables
I'm getting an error when I pass a string to an NSURL.
Entity: line 6: parser error : EntityRef: expecting ';'
zzzzzzz.com/feeds/rss/zzzz/zzzz/get_feed.php?c=zzzz&s=zzzz&f
It doesn't stop the app or anything but I feel like it should be addressed. Looks like it doesn't like the &
symbol. I tried replacing with &
but that doesn't do the trick.
NSString *blogAddress = @"http://zzzzzz.com/feeds/rss/zzzz/zzzz/get_feed.php?c=zzzz&s=zzzz&f=most_recent";
NSURL *url = [NSURL URLWithString: blogAddress];
CXMLDocument *rssParser = [[[CXMLDocument alloc] initWithContentsOfURL:url options:0 error:nil] autorelease];
Try encoding your URL string like this...
NSURL *url = [NSURL URLWithString:[blogAddress stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
You need to URLEncode your String. I used a category to do it:
URLUtils.h:
@interface NSString (URLUtils)
- (NSString *) urlEncodeValue;
@end
URLUtils.m:
#import "URLUtils.h"
@implementation NSString (URLUtils)
- (NSString *) urlEncodeValue {
return (NSString *) CFURLCreateStringByAddingPercentEscapes(NULL,
(CFStringRef) self,
NULL,
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
kCFStringEncodingUTF8 );
}
@end
Then after including URLUtils.h
in your class, you can do this:
NSURL *url = [NSURL URLWithString: [blogAddress urlEncodeValue]];
That should do it.
Good Luck!
精彩评论