1

我正在使用 Appcelerator Titanium,下面的代码在 iPhone 上运行良好,但在 Android 上运行良好,我无法找出原因。任何人都可以帮忙吗?

它失败并出现以下错误:

TypeError:无法从 null 读取属性“DocumentElement”

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: " + 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
4

1 回答 1

0

这就是我所做的并且有效

请换行 Ti.XML.parseString(this.responseText).documentElement;

this.responseXML.documentElement它应该可以工作。这是它的输出。我还没有在 OS X 上测试过它,但它应该可以工作。

[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
于 2011-03-21T00:35:49.290 回答