Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

responseXML is always null

Am I missing something or is this a known issue? I have tried it with several feed sources with no luck.

var xhr = Titanium.Network.createHTTPClient();
xhr.onload = function() {
  console.log(this);
}
xhr.onreadystatechange = function() { }
xhr.open('GET','http://twoism.posterous.com/rss.xml');
xhr.send();

From web inspector:


responseData: Object
responseText: "<?xml version="1.0" encoding="UTF-8"?> <rss xm<snip>"
responseXML: null
— asked July 22nd 2010 by Christopher Burnett
  • desktop
  • responsexml
0 Comments

4 Answers

  • Here's the code we're using to fill out the missing responseXML on both Desktop and Mobile:

    var responseXML;
    if (this.responseXML == null) {
        if (typeof DOMParser != "undefined") {
            // Titanium Desktop 1.0 doesn't fill out responseXML.
            // We'll use WebKit's XML parser...
            responseXML = (new DOMParser()).parseFromString(this.responseText, "text/xml");
        } else {
            // Titanium Mobile 1.3 doesn't fill out responseXML on Android.
            // We'll use Titanium's XML parser...
            responseXML = Titanium.XML.parseString(this.responseText);
        }
    } else {
        responseXML = this.responseXML;
    }
    
    — answered July 27th 2010 by Brion Vibber
    permalink
    1 Comment
    • Hi Brion,
      I am using Ti Desktop 1.2.0 and I am facing issue in parsing the xml string that I am getting in response. We are trying to get node value from child node but not getting any value, its displaying blank when using element[0].childNodes[0].nodeValue. We also tried with element[0].childNodes[0].text but that gives as undefined.

      In your example if you can please show how xml can be parsed further after this steps then it would be a great help.

      Thank You in advance.

      — commented January 25th 2012 by Priyanka Patel
  • I don't have no problem with that.

    var xhr = Titanium.Network.createHTTPClient();
    xhr.onload = function(e) {
      Ti.API.info(this.responseText);
    }
    xhr.onreadystatechange = function() { }
    xhr.open('GET','http://twoism.posterous.com/rss.xml');
    xhr.send();
    

    and got the entire rss feedback

    — answered July 22nd 2010 by Daniel Lim
    permalink
    1 Comment
    • i can get the responseText just not responseXML. Try…

      Ti.API.info(this.responseXML);
      

      — commented July 22nd 2010 by Christopher Burnett
  • Make sure the Content-Type of the response is "text/xml" or "application/xml"

    — answered July 27th 2010 by Chris Farmiloe
    permalink
    0 Comments
  • Brion's answer almost solved my problem.

    I also always have an empty responseXML, but also an empty responseText! (APIs 2.2, Ti 1.5.0)
    Fortunately my responseData was containing the right response so I could use it.
    So if responseText is also null, use responseData.toString() instead.
    Then Brion's code does the job.

    It worked for me.

    — answered January 31st 2011 by Thomas Dall'Agnese
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.