XML解析Android上的失败,而是适用于iPhone [英] XML Parsing failure on Android but works on iPhone

查看:243
本文介绍了XML解析Android上的失败,而是适用于iPhone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Appcelerator的问答集的链接:
<一href=\"http://developer.appcelerator.com/question/128341/xml-parsing-failure-on-android-but-works-on-iphone\"相对=nofollow> XML解析失败于Android,但适用于iPhone

我是preparing这既为iPhone和Android手机与同一code,对于它钛majorly用于工作的一般应用。在相同的code我发现XML文档解析不同的结果和我的Andr​​oid应用程序不能正常加载它。它会导致空指针异常。但是,同样的code完美的作品在iPhone上。

您可以检查这个?

  XYZ(语言code,CURRENTVERSION,xmlDoc中){
尝试{
  Ti.API.info('开始解析库');
  VAR archiveData = xmldoc.getElementsByTagName('归档');
  Ti.API.info(存档:'+ archiveData);
  Ti.API.info('项目:'+ archiveData.item);
  Ti.API.info('Lendth:'+ archiveData.length);
  VAR NEWVERSION = archiveData.item(0).getAttribute('版本');
}赶上(E){
  Ti.API.info('图书馆进去抓:'+ E);
}

函数调用:Ti.Network.HttpClient的这是一个从onload事件()方法


  

XYZ(语言code,版本this.responseXML.documentElement);


iPhone的输出:


  

存档:[对象TiDOMNodeList]


  
  

[INFO]项目:对象TiDOMNodeList]


  
  

[INFO] Lendth:1


Android的输出:


  

[INFO] [3,7225]存档:[Ti.NodeList]


  
  

[INFO] [1,7226]项目:[KrollMethod项目]


  
  

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


  
  

[235,7466]图书馆进去抓:JavaException:显示java.lang.NullPointerException:空



解决方案

检查链接:

<一个href=\"http://developer.appcelerator.com/question/128341/xml-parsing-failure-on-android-but-works-on-iphone#comment-104281\" rel=\"nofollow\">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(语言code,版本,XML);

this.responseXML.documentElement。它在Android上的一些问题(不知道是该公司报告或不)。解决方法是用Ti.XML.parseString的方法来重新解析XML:

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

解决方案

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:.

这篇关于XML解析Android上的失败,而是适用于iPhone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆