xml

You must Login before you can answer or comment on any questions.

I have xml file like <project id="1">

<title> Wimbledon</title></project> now i want to read title of project having id=1 .How can i do this??

2 Answers

Accepted Answer

hi Lokesh,

try this

var txt = '<project id="1"><title> Wimbledon</title></project>';
var d = Ti.XML.parseString(txt);
 
var doc = d.getElementsByTagName('project');
if(doc.item(0).getAttribute('id') == 1) {
    alert(doc.item(0).getElementsByTagName('title').item(0).text);
}

— answered 1 year ago by Mitul Bhalia
answer permalink
17 Comments
  • Thankyou Mitul.:)

    — commented 1 year ago by Lokesh Gupta

  • but Mitul..if i have 10 project id's then how can i get other id's data??.....

    — commented 1 year ago by Lokesh Gupta

  • you can use for loop for that

    for(var i = 0; i < doc.length; i++){
     
    if(doc.item(i).getAttribute('id') == 1) {
        alert(doc.item(i).getElementsByTagName('title').item(0).text);
    }
    }

    — commented 1 year ago by Mitul Bhalia

  • Show 14 more comments

Hi Lokesh, you ´can use the XML-Lib: http://docs.appcelerator.com/titanium/2.0/index.html#!/api/Titanium.XML

Your Answer

Think you can help? Login to answer this question!