简体   繁体   English

使用Appcelerator从XML解析和提取数据

[英]Parse and extract data from XML using Appcelerator

Titanium SDK version: 1.6.1 Titanium SDK版本:1.6.1
iPhone SDK version: 4.2 iPhone SDK版本:4.2

I am having a hard time extracting the data from this XML output in Appcelerator. 我很难从Appcelerator中的XML输出中提取数据。 I would like to get the token and the username. 我想获得令牌和用户名。 How is this done? 这是怎么做到的?

<rsp stat="ok">
<auth>
<token>73257626300602415-3324a12587e2e9b3602</token>
<perms>delete</perms>
<user nsid="599323339@N047" username="theuser200" fullname="" />
</auth>
</rsp>

Thankful for all input. 感谢所有输入。

Presuming your xml came from am xhr request then. 假设您的xml来自am xhr请求。

xhr.onload = function() {
  var doc = this.responseXML.documentElement; // Give me a xml document.
  var token = doc.getElementsByTagName("token").item(0).text; // Get the token element, then the first item (could be lots of them) then the text of the first.
  var username = doc.getElementsByTagName("user").item(0).getAttribute("username"); // Ditto as above, but this time get the attribute name "username"
}

Have you read the API documentation ? 您是否阅读过API文档

Titanium.XML starts on page 506 Titanium.XML从第506页开始

Also, this guide may be of some help. 此外, 本指南可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM