1

Appcelerator 问答链接: Android 上的 XML 解析失败,但在 iPhone 上有效

我正在准备一个通用应用程序,它适用于 iPhone 和 Android 手机,其代码与 Titanium 主要用于相同的代码。使用相同的代码,我发现 XML 文档解析的结果不同,并且我的 android 应用程序无法正确加载它。它会导致 NULLPointer 异常。但同样的代码在 iPhone 上也能完美运行。

你能检查一下吗?

xyz(languageCode, currentVersion, xmldoc) {
try {
  Ti.API.info('Start parsing the library');
  var archiveData = xmldoc.getElementsByTagName('archive');
  Ti.API.info('Archive: ' + archiveData);
  Ti.API.info('Item: ' + archiveData.item);
  Ti.API.info('Lendth: ' + archiveData.length);
  var newVersion = archiveData.item(0).getAttribute('version');
}catch(e){
  Ti.API.info('Library Went In Catch: ' + e);
}

函数调用:来自 Ti.Network.HttpClient 的 onload() 方法

xyz(语言代码,版本,this.responseXML.documentElement);

iPhone的输出:

存档:[对象 TiDOMNodeList]

[INFO] 项目:[对象 TiDOMNodeList]

[信息] 长度:1

安卓的输出:

[信息] [3,7225] 存档:[Ti.NodeList]

[信息] [1,7226] 项目:[KrollMethod 项目]

[信息] [2,7228] 长度:0 [信息]

[235,7466] 库进入 Catch:JavaException:java.lang.NullPointerException:null

4

1 回答 1

0

检查链接:

http://developer.appcelerator.com/question/128341/xml-parsing-failure-on-android-but-works-on-iphone#comment-104281

使用以下方法解析 XML:

var xml = Ti.XML.parseString(this.responseXML.toString());

xyz(languageCode, version, xml);

“this.responseXML.documentElement”。它在 Android 上有一些问题(不知道有没有报告)。解决方法是使用“Ti.XML.parseString”方法重新解析 XML:。

于 2011-11-17T10:46:24.813 回答