Has anyone ever tried to use XML & XSLT in WKWebView, with the files included in the app bundle?
I.e. example.xml:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="transform.xslt"?>
<page>
</page>
transform.xslt:
<xsl:transform
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<xsl:template match="page">
<html>
<body>
<p>Hello World</p>
</body>
</html>
</xsl:template>
</xsl:transform>
When I attempt to load that as file:///path/to/bundle/example.xml,
I get a blank page (and nothing in the console).
Various questions:
-
I know that generally web console output inside apps doesn't appear in the logs, and there are various suggestions about injecting user scripts to fetch them by replacing e.g. console.log. But does that only fetch errors generated by Javascript, or does it also fetch other error messages? Should I be able to attach to my WKWebView's console from Safari on my Mac, over USB?
-
If I try to view the same file using a file: URL in Safari on my Mac, I discover that security policy prevents a file: XML document from using a file: XSLT even if they are in the same directory; it considers all file: URLs to have different origins. I don't see that error with the WKWebView, hence question (1).
-
Is there anything that I can do with WKWebView to permit access from a file: XML document to a file: XSLT document in the same directory, within the app bundle? I have tried using
loadURL: allowingReadAccessToURL:,
and that doesn't seem to work. I'm also aware of theWKSecurityOrigin
type, and I wonder if I can use that to persuade WKWebView that the XML and XSLT are "same origin". Does this require that I implement a "content blocker"? Can a content blocker ever relax restrictions, rather than tightening them?
Thanks for any suggestions!