Last active
August 29, 2015 13:58
-
-
Save csemrm/10002696 to your computer and use it in GitHub Desktop.
How to access XML element by attribute id?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var self = Ti.UI.createWindow({ | |
backgroundColor : '#fff' | |
}); | |
var xhr = Titanium.Network.createHTTPClient(); | |
var aTableView = Ti.UI.createTableView(); | |
xhr.onload = function() { | |
//Ti.API.info('http://appc.mrtechnologybd.com/node.xml ' + this.responseXML + ' text ' + this.responseText); | |
var doc = this.responseXML.documentElement; | |
var data = []; | |
var items = doc.getElementsByTagName("animal"); | |
for (var i = 0; i < items.length; i++) { | |
var type = items.item(i).getElementsByTagName("type").item(0).getAttribute('id'); | |
data.push({ | |
title : type | |
}); | |
} | |
aTableView.setData(data); | |
self.add(aTableView); | |
}; | |
xhr.onerror = function(e) { | |
Ti.API.info('error:' + e.error); | |
}; | |
// open the client | |
xhr.open('GET', 'http://appc.mrtechnologybd.com/node.xml'); | |
// send the data | |
xhr.send(); | |
self.open(); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<animals> | |
<animal> | |
<type id="mammal"> | |
<kind>Dog</kind> | |
<name>Duke</name> | |
</type> | |
</animal> | |
<animal> | |
<type id="Reptile"> | |
<kind>Frog</kind> | |
<name>Kermit</name> | |
</type> | |
</animal> | |
</animals> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment