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
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; }
-
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
-
Make sure the Content-Type of the response is "text/xml" or "application/xml"
-
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.