Thursday 10 July 2014


Titanium XML Parse and extract data  : 

Example : 

<Response stat="ok">
     <auth>
          <token> 73257626300602415 - 3324a12587e2e9b3602</token>
          <params>delete</params>
          <userid = "23232" username="ABC" fname="A"/>
     </auth>
</Response>

 

Solve like this : 

Presuming your xml came from am xhr request then.

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

No comments:

Post a Comment