XML Parsing failure on Android but works on iPhone

蹲街弑〆低调 提交于 2019-12-24 10:44:05

问题


Appcelerator Q&A Link: XML Parsing failure on Android but works on iPhone

I am preparing a general application which works both for iPhone and Android phones with same code for which Titanium is majorly used for. With the same code I found different results for XML document parsing and my android app does not load it properly. It causes NULLPointer Exception. But the same code works perfectly on iPhone.

Can you check this?

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);
}

Function call: It's from onload() method of Ti.Network.HttpClient

xyz(languageCode, version,this.responseXML.documentElement);

Output of iPhone:

Archive: [object TiDOMNodeList]

[INFO] Item: [object TiDOMNodeList]

[INFO] Lendth: 1

Output of Android:

[INFO] [3,7225] Archive: [Ti.NodeList]

[INFO] [1,7226] Item: [KrollMethod item]

[INFO] [2,7228] Lendth: 0 [INFO]

[235,7466] Library Went In Catch: JavaException: java.lang.NullPointerException: null


回答1:


Check the link:

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

For parsing XML using:

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

xyz(languageCode, version, xml);

"this.responseXML.documentElement". It has some problems on Android (don't know is it reported or not). The workaround it to use "Ti.XML.parseString" method to re-parse XML:.



来源:https://stackoverflow.com/questions/8163385/xml-parsing-failure-on-android-but-works-on-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!