【问题标题】:Parse and extract data from XML using Appcelerator使用 Appcelerator 从 XML 中解析和提取数据
【发布时间】:2017-04-16 05:26:35
【问题描述】:

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

我很难从 Appcelerator 中的 XML 输出中提取数据。我想获取令牌和用户名。这是怎么做到的?

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

感谢所有输入。

【问题讨论】:

标签: xml appcelerator


【解决方案1】:

假设您的 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"
}

【讨论】:

    【解决方案2】:

    你读过the API documentation吗?

    Titanium.XML 从第 506 页开始

    另外,this guide 可能会有所帮助。

    【讨论】:

    • 这是非常标准的 DomDocument 东西。您以前没有使用过基于 DOM 的解析器吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多