开发者

Parse and extract data from XML using Appcelerator

开发者 https://www.devze.com 2023-02-22 14:39 出处:网络
Titanium SDK version: 1.6.1 iP开发者_如何转开发hone SDK version: 4.2 I am having a hard time extracting the data from this XML output in Appcelerator. I would like to get the token and the username.

Titanium SDK version: 1.6.1

iP开发者_如何转开发hone SDK version: 4.2

I am having a hard time extracting the data from this XML output in Appcelerator. 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.

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?

Titanium.XML starts on page 506

Also, this guide may be of some help.

0

精彩评论

暂无评论...
验证码 换一张
取 消