XHR documentElement with HTML not XML

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

Hi I'm trying to get the content on an HTML document to manipulate but am having problems using documentElement.

Is that only available when working with XML? If so, is there a way to do anything similar when fetch from an HTML webpage?

Here is my code:

var xhr = Ti.Network.createHTTPClient();
xhr.onload = function(){
if (this.status == 200) {
    var doc = this.responseText;
    var result = doc.documentElement;
}
};
xhr.open("GET","DOMAIN_NAME");
xhr.send();
the variable doc returns the contents of the website ok, but when I use doc.documentElement the variable result is empty, so using getElementsByID or anything else similar won't find anything.

— asked 3 years ago by Luke Peek
0 Comments

3 Answers

You can always use WebView component. :)

— answered 3 years ago by Ivan Škugor
answer permalink
2 Comments
  • Thanks Ivan, I really want to get the content so I can manipulate it within the app, not just display the webpage. Thanks though!

    — commented 3 years ago by Luke Peek

  • Well ... I was suggesting that. :)

    Create WebView (don't add it to the window!) and use standard DOM methods to get what you want from HTML and then transfer that data to the rest of your app by using app-level events.

    — commented 3 years ago by Ivan Škugor

HI,

i suppose this.responseTest returns string.

— answered 3 years ago by Satta Ravi
answer permalink
7 Comments
  • Hi Sattanaathan, Yes there is a valid response, (this is the contents on the entire html document)

    — commented 3 years ago by Luke Peek

  • Hi Luke,

    i got one question, why do you wanna do a DOM operation on a String?

    My bet would be to parse the string to strip out the data thats needed drive your app.

    — commented 3 years ago by Satta Ravi

  • That is what HTML parser does. :P

    — commented 3 years ago by Ivan Škugor

  • Show 4 more comments

Ok thanks! I don't particularly want to do anything DOM, I know thats not possible. but in all the examples ive seen (including kitchensink) the way to process XML feeds is using these DOM operations. I thought I would ask if it was possible on HTML instead of XML.

Your Answer

Think you can help? Login to answer this question!