Project

Profile

Help

state of the art with respect to cross domain

Added by Jim Fuller over 7 years ago

whats the best idiom for dealing with pulling down data using fn:doc these days with saxon-ce ?


Replies (2)

RE: state of the art with respect to cross domain - Added by Michael Kay over 7 years ago

Well, there's no Saxon-CE specific answer to the cross-domain issue, if that's what you mean. I haven't tried CORS, as described here for example

https://www.bionicspirit.com/blog/2011/03/24/cross-domain-requests.html

but I don't know any reason why it shouldn't work.

The other issue with fn:doc() is that it's synchronous, which isn't too friendly; I think that judicious use of ixsl:schedule-action can help to limit the damage (ie. to reduce the amount of time the browser is unresponsive to user input).

RE: state of the art with respect to cross domain - Added by Philip Fearon over 7 years ago

An alternative is to use a server-side service to act as a 'reverse-proxy' - where you append the required URL as an agrument in the HTTP request to your own server so its not cross-domain. Your own server then makes the request using the URL parameter on behalf of the client and returns the response in the usual way

This is the approach "PathEnq":http://www.qutoric.com/xslt/analyser/xpathtool.html takes. It calls a JavaScript function @addFileFromURL@ from the XSLT to allow async behaviour, with the JS response handler adding a button when the response is complete. The XSLT then resumes when the user clicks the new button (there's a ready-made XSLT template that matches the click event of this button). Further JS function calls are made from the XSLT whenever data from the HTTP response is required (because the response is not added to the document pool).

I wouldn't call this state of the art, but it does work and it is relatively simple to implement both on the client and the server.

The JavaScript that PathEnq uses:


var addFileFromURL = function (xmlURL) {
    var fullURL = "../../proxy.ashx?" + xmlURL;
    getFile(fullURL);
}

var getFile = function (xmlURL) {
    var xmlhttpURL = xmlURL;
    if (typeof XMLHttpRequest == "undefined") {
        XMLHttpRequest = function () {
            try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); }
            catch (e) { }
            try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); }
            catch (e) { }
            try { return new ActiveXObject("Microsoft.XMLHTTP"); }
            catch (e) { }
        };
    }
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = handleStateChange(xmlhttp, xmlhttpURL);

    xmlhttp.open("GET", xmlhttpURL, true);
    xmlhttp.send(null);
};

var handleStateChange = function (inXmlHttp, inXmlURL) {
    var xmlhttp = inXmlHttp;
    var xmlURL = inXmlURL;
    var returnFunction = function () {
        switch (xmlhttp.readyState) {
            case 0: // UNINITIALIZED
            case 1: // LOADING
            case 2: // LOADED
            case 3: // INTERACTIVE
                break;
            case 4: // COMPLETED
                handleResponse(xmlhttp.status, xmlhttp.responseText, xmlURL);
                break;
            default: alert("error");
        }
    }
    return returnFunction;
}

    (1-2/2)

    Please register to reply