0

I added TestXML.xml together with simple.xls file to my Resources folder. Now I want to display the xml styled according to the xsl file.

string fileName = "TestXML.xml";
string localDocUrl = Path.Combine (NSBundle.MainBundle.BundlePath, fileName);
NSUrl url = new NSUrl (localDocUrl, false);
NSData xml = NSData.FromUrl (url);

string contentDirectoryPath = NSBundle.MainBundle.BundlePath;
NSUrl baseURL = new NSUrl (contentDirectoryPath, true);
webView.LoadData (xml, "text/xml", "UTF-8", baseURL);
webView.ScalesPageToFit = false;

If I execute the code above I get an empty page. How do I load the styled XML file onto my UIWebView?

EDIT

Now I tried to load a web ressource:

string fileName = "http://www.w3schools.com/xml/simplexsl.xml";
NSUrl url = new NSUrl(fileName);
NSMutableUrlRequest request = new NSMutableUrlRequest (url, NSUrlRequestCachePolicy.ReloadIgnoringLocalAndRemoteCacheData, 10);
webView.LoadRequest(request);

Here the xml file is correctly loaded with the xsl file. But how could I use a string or a local file for displaying it in the UIWebView?

testing
  • 19,681
  • 50
  • 236
  • 417
  • Just noticed there's someone having the opposite problem - he wants to load an xml from web but his code only worked for local xml; maybe useful: http://stackoverflow.com/questions/17791317/uiwebview-xml-file – matthias_h Aug 23 '14 at 02:10
  • @matthias_h: I tried to replicate the code: `var path = NSBundle.MainBundle.PathForResource("TestXml","xml"); NSData xmlData = NSData.FromFile(path); webView.LoadData (xmlData, "text/xml", "utf-8", new NSUrl (NSBundle.MainBundle.BundlePath, true));` The xml data is loaded and the webview gives no error but the screen is white ... If I use `webView.LoadData (xmlData, "text/text", "utf-8", NSUrl.FromString(""));` than I get the textual representation of the xml file but no rendering. – testing Aug 24 '14 at 14:15
  • If I use `var stringXML = File.ReadAllText("TestXml.xml"); webView.LoadHTMLString(stringXML, NSUrl.FromString(""));` I get the text without formatting. Is the path wrong? I also tried it with `new NSUrl (NSBundle.MainBundle.BundlePath, true)` as path but its still wrong... – testing Aug 24 '14 at 14:27
  • Possible duplicate of [XLST in a UIWebView using iOS SDK 4.2](https://stackoverflow.com/questions/5100051/xlst-in-a-uiwebview-using-ios-sdk-4-2) – Paul Sweatte Sep 27 '17 at 14:48

0 Answers0