How do I load XML from a webView

You must Login before you can answer or comment on any questions.

I have a webView in my Titanium mobile application that loads a login page, allows the user to log into the site, and then once the user has logged in and has loaded the main page, an XML file is loaded from a link on the web page. When the XML loads in the webView, I can see the elements of the XML listed out in the webView.

webView.addEventListener('load',function(e) {
                Ti.API.info('The URL changed to '+webView.url);
                if (webView.url == "****my main page url****") {
                    Ti.API.info("Got the main page");
                    webView.hide();
                    webView.evalJS('window.location = "****my xml url****"');
                } else if (webView.url == "****my xml url****") {
                    Ti.API.info("XML Loaded");
                    parseXML();
                }
         });
        parseXML = function() {
            xmlContent = webView.getHtml();
            Ti.API.info(xmlContent);
        }
What I need to do is get this XML data out of the webView and parse it, and do various things with it. I can not seem to find a way to retrieve this out of the webView. I also tried:
xmlContent = webView.evalJS("document");
I have no idea if that is the proper thing to do...but it didn't work.

Does anyone have a solution to this problem, or another way to work this without using a webView. The reason I am not fetching a file using XHR is that the site uses Digest authentication, which can not be done using XHR as far as I know.

2 Answers

Hi ian

It is possible to do digest authentication using xhr and once you have automated the handshake you should find this process easier than trying to scrape the web view.

Example 1

Example 2

— answered 11 months ago by Malcolm Hollingsworth
answer permalink
2 Comments
  • These links refer to PHP and jQuery code. Could you please give me a little assistance with starting to implement one of these?

    — commented 11 months ago by Ian McDowell

  • Hi Ian

    The provided examples are for jQuery and PHP, but the information and how to examples of setting the content header are right in those documents and with a bit of effort can be translated.

    You will need to use the setRequestHeader and getResponseHeader methods of the xhr object.

    — commented 11 months ago by Malcolm Hollingsworth

I think it is not a problem to build the special http header. It is the same way lie with oauth.

Your Answer

Think you can help? Login to answer this question!