views:

21

answers:

1

Hi guys

I have the following url http://gdata.youtube.com/feeds/api/standardfeeds/recently_featured?&start-index=1&max-results=15&v=2

I am trying to load it in UIWebView and then use javascript to get its contents, and parse it with NSXMLParser.

My code looks like that:

-(void)startDownloading{
    NSString *urlStr = [NSString stringWithFormat:@"http://gdata.youtube.com/feeds/api/standardfeeds/recently_featured?&start-index=%d&max-results=%d&v=2", range.location, range.length];
 NSLog(urlStr);
 NSURL *url = [NSURL URLWithString:urlStr];

 NSURLRequest *request = [NSURLRequest requestWithURL:url];
     [browser loadRequest:request];

    }

    - (void)webViewDidFinishLoad:(UIWebView *)webView{

     NSString *theStr = [webView stringByEvaluatingJavaScriptFromString:@"document.body.firstChild.innerHTML"];
     NSLog(theStr);
     NSData *receivedData = [theStr dataUsingEncoding:NSUTF8StringEncoding];

    }

the problem is that the data that I receive can't be parsed with NSXMLParser. The text looks like that: <?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:app='http://www.w3.org/2007/app' xmlns:media='http://search.yahoo.com/mrss/' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' xmlns:gd='http://schemas.google.com/g/2005' xmlns:yt='http://gdata.youtube.com/schemas/2007' gd:etag='W/&quot;DUADR347eCp7ImA9Wx5UFkg.&quot;'><id>tag:youtube.com,2008:standardfeed:us:recently_featured</id><updated>...

while if I had used just the regular approach of getting data (without browser) I would get:

<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:app='http://www.w3.org/2007/app' xmlns:media='http://search.yahoo.com/mrss/' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' xmlns:gd='http://schemas.google.com/g/2005' xmlns:yt='http://gdata.youtube.com/schemas/2007' gd:etag='W/&quot;DUADR347eCp7ImA9Wx5UFkg.&quot;'><id>tag:youtube.com,

Why are the characters changing? And how can I prevent it

BTW to those who are wondering why I'm even bothering to do this - I think that this method gets the data quicker.

A: 

The data is being escaped, you need to unescape it. Take a look at:

- (NSString *)stringByReplacingPercentEscapesUsingEncoding:(NSStringEncoding)encoding

"BTW to those who are wondering why I'm even bothering to do this - I think that this method gets the data quicker."

Don't prematurely optimize.

Matt Lilek
This doesn't work for me (UTF8 and ASCII encodings don't work). Are you sure it's not for URL only?
Alex1987