0SX
0SX

Reputation: 1292

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 working with UIWebView?

Thanks

Upvotes: 0

Views: 850

Answers (2)

Rubycon
Rubycon

Reputation: 18346

NSString *webViewBody = [webView stringByEvaluatingJavaScriptFromString: @"(new XMLSerializer()).serializeToString(document);"];

Upvotes: 0

Mike D.
Mike D.

Reputation: 26

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]

Upvotes: 1

Related Questions