开发者

Why does this Appcelerator code work on iPhone but not on Android?

I am using Appcelerator Titanium and the code below works fine on iPhone but not on Android and I am unable to find out why. Can anyone help?

It fails with the following error:

TypeError: Cannot read property "DocumentElement" from null

BEGIN CODE

var xhr = Titanium.Network.createHTTPClient();

xhr.onload = function() {
   var xmlDoc = Ti.XML.parseString(this.responseText).documentElement;
   var xlinestatus = xmlDoc.getElementsByTagName('LineStatus');

   for (i = 0; i < xlinestatus.length; i++) {
     var theItem = xlinestatus.item(i);
     var newname = theItem.getElementsByTagName("Line").item(0).getAttribute("Name");
     var desc = theItem.getElementsByTagName("Status").item(0).getAttribute("Description");
     var active = theItem.getElementsByTagName("Status").item(0).getAttribute("IsActive");
     Ti.API.info(" Line: "开发者_JS百科 + newname + " Status: " + desc + ", Active: " + active);
   }

};

// open the client
xhr.open('GET', 'http://cloud.tfl.gov.uk/TrackerNet/LineStatus');

// send the data
xhr.send({});

END CODE


This is what I did and it worked

please change the line Ti.XML.parseString(this.responseText).documentElement;

to

this.responseXML.documentElement and it should work. Here is the output of it. I haven't tested it on OS X but it should work.

[INFO] [157,5791] Line: Bakerloo Status: Service Closed, Active: true
[INFO] [8,5799] Line: Central Status: Service Closed, Active: true
[INFO] [27,5826] Line: Circle Status: Service Closed, Active: true
[INFO] [7,5833] Line: District Status: Service Closed, Active: true
[INFO] [16,5849] Line: Hammersmith and City Status: Service Closed, Active: true
[INFO] [11,5860] Line: Jubilee Status: Service Closed, Active: true
[INFO] [12,5872] Line: Metropolitan Status: Service Closed, Active: true
[INFO] [12,5884] Line: Northern Status: Service Closed, Active: true
[INFO] [14,5898] Line: Piccadilly Status: Service Closed, Active: true
[INFO] [14,5912] Line: Victoria Status: Service Closed, Active: true
[INFO] [14,5926] Line: Waterloo and City Status: Service Closed, Active: true
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜