Can't get value from xml doc
I have a web service that is returning the following xml data.
<string xmlns="https://www.mysecuredserver.com/webservices/">2192.25</string>
I am trying to parse out 2192.25 but can't seem to get it to work. I have ried the following.
function constructAndSend(){
xhr.open("GET","https://www.mysecuredserver.com/webservices/pimswareservice.asmx/GetGatewayRevenue?freq=" + frequency);
xhr.send(null);
}
buttonRefresh.addEventListener('click', function(e)
{
lblBBIndex.text = 'You clicked index = ' + frequency;
constructAndSend();
});
xhr.onload = function()
{
xmlDoc = this.responseXML;
try{
xmlDoc.getElementsByTagName("string")[0].childNodes[0].nodeValue;
var xmlAmount = xmlDoc.getElementsByTagName("document")[0].nodValue;
} catch(err) {
var e = Titanium.UI.createAlertDialog();
e.setTitle("Error");
e.setMessage(err);
e.show();
}
};
bb1.addEventListener('click', function(e)
{
frequency = e.index;
});
any suggestions? I am just trying to pull out the value and place it into a label.
Thanks in advance!!
Chad
3 Answers
-
Hi Chad,
This is the structure I use, it seems to work OK:
var itemList = response.documentElement.getElementsByTagName('item'); for (var c=0;c < itemList.length;c++){ myGuid = itemList.item(c).getElementsByTagName("guid").item(0).text; };
cheers,
Chris -
My XML output:
<result> <user> <fbid>1321613213215</fbid> <name>Jeff</name> </user> </result>
Parsing is as follows:
if(statusCode == 200) { Ti.API.info('>>> got the contacts xml! ... '); var xml = GETRequest.responseXML; Titanium.API.log("info","Response: "+xml); var result = xml.documentElement.getElementsByTagName("result"); var itemList = xml.documentElement.getElementsByTagName("user"); Ti.API.info('got item list'); var cdata = []; //var id_text = $(this).attr('id'); var fbid_text = itemList.item(0).getElementsByTagName("fb_ID").item(0).text; var name_text = itemList.item(0).getElementsByTagName("name").item(0).text; }
-
Chris,
Thanks for the response. When you refer to 'item', is this a name of an xml node or does it just mean an item of the tree? I am assuming that "guid" is the name of an xml node. I updated my code to follow what you send and I am now getting the following error.
"Result of expression 'itemLIst' [null] is not an object."
Any ideas?