How to get xml source code from UIWebView?
I am using a UIWebView to exact source from a webpage however I can't get it to work for xml files. Here the code I'm using:
NSString *xml = [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.textContent"];
However this doesn't give me the XML source tags. Anyone got any ideas?
This works for html documents but not for xml documents, it seems. How can I get this 开发者_如何学Pythonworking with UIWebView?
Thanks
You are trying to use JavaScript, which cannot be executed in an XML document.
If you know the URL of the XML document, you can use [NSData dataWithContentsOfURL:(NSURL*)URL]
NSString *webViewBody = [webView stringByEvaluatingJavaScriptFromString: @"(new XMLSerializer()).serializeToString(document);"];
精彩评论