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>
感谢所有输入。
答案 0 :(得分:2)
假设您的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"
}
答案 1 :(得分:0)