Question: I've been trying to display a xml file in my uiwebview. I've tried using NSURLRequest but the UIWebview shows up blank. I am able to display a local xml using the code below. Is there a way pull this from a defined website rather than from local file or maybe download the file then display it? 

```
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"location" ofType:@"xml"];
NSData *htmlData = [NSData dataWithContentsOfFile:htmlFile];
[aWebView loadData:htmlData MIMEType:@"text/text" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@""]];

```

Answer: 
Set your `UIWebView` delegate and define [`webView:didFailLoadWithError:`](http://developer.apple.com/library/ios/documentation/uikit/reference/UIWebViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIWebViewDelegate/webView%3adidFailLoadWithError%3a) and [`– webViewDidFinishLoad:`](http://developer.apple.com/library/ios/documentation/uikit/reference/UIWebViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIWebViewDelegate/webViewDidFinishLoad%3a); if you put some `NSLog` traces in there (or break into them with the debugger), you might understand what is happening.

In principle, if you can display a local file, you can display the same info coming from a remote server. So I am thinking that maybe your server is not replying correctly (and `didFail:` will help you understanding that).

EDIT:

The mimetype is sent by the server, and I am not aware of a way to modify it before the `UIWebView` gets to handle it.

You can easily download a file by way of:

```
NSData *urlData = [NSData dataWithContentsOfURL:url];

```

and then you can pass the data into the web view as you are already doing.

Take into account that `dataWithContentsOfURL:` is sync, so it will halt your UI (but for a test it is ok). If everything works out well, then you can run it on a background thread, that would be something like:

```
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

    NSData *htmlData = [NSData dataWithContentsOfURL:url];
    dispatch_async(dispatch_get_main_queue(), ^{

       [aWebView loadData:htmlData MIMEType:@"text/text" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@""]];

    }
}

```

Notice how getting back to the `UIWebView` once the XML has been downloaded is done through the main thread.
Please use below code for load local xml file from document directory in uiwebview 

```
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"demo.xml"];

NSString *content = [NSString stringWithContentsOfFile:dataPath encoding:NSUTF8StringEncoding error:NULL];

NSLog(@"contenct %@",content);

[webView loadHTMLString:[NSString stringWithFormat:@"<html><body>%@</body></html>",content] baseURL:nil];

```