0

I have XML file in the following format,

In data1 array, i am getting first 'webportal:highResUrl' value, but not all values (i.e 'webportal:highResUrl' contains 2 values). I am getting repeated values in data1 array.

<root>
<item>
 <webportal:files>
  <webportal:highResUrl>http://xxx.xom/image</webportal:highResUrl>
  <webportal:highResUrl>http://xxx.xom/image</webportal:highResUrl>     
 </webportal:files> 
</item>
<item>
<webportal:files>
  <webportal:highResUrl>http://xxx.xom/image</webportal:highResUrl>
  <webportal:highResUrl>http://xxx.xom/image</webportal:highResUrl>     
 </webportal:files>
</item>
</root>



 var data = []; 
    var data1=[];   
    var xhr = Ti.Network.createHTTPClient();        
    xhr.onload = function()
    {       
            var doc = this.responseXML.documentElement;
            var items = doc.getElementsByTagName("item");       
            for (var c=0;c<items.length;c++)
            {                   
                var item = items.item(c);
                var sTitle1 = item.getElementsByTagName("title").item(0).text;
                var itemswebportal=item.getElementsByTagName("webportal:files");

                    for(var j=0;j<itemswebportal.length;j++){   

                        var sTeamHighResouImage = item.getElementsByTagName("webportal:highResUrl").item(0).text
                        data1.push({
                        path: sTeamHighResouImage,
                        });             
                     }}}
    };
    xhr.send(); 

1 Answer 1

1

Because you are getting only one value from the <webportal:highResUrl>

item.getElementsByTagName("webportal:highResUrl").item(0).text

The above line returns only the text of first <webportal:highResUrl>. It seems to be a static one so just make it over a loop to get all the values

for(var j=0;j<itemswebportal.length;j++){   
   for(var k=0;k<item.getElementsByTagName("webportal:highResUrl").length;k++)
                     {
                        var sTeamHighResouImage = item.getElementsByTagName("webportal:highResUrl").item(k).text
                        data1.push({
                        path: sTeamHighResouImage,
                        });             
                     }}
Sign up to request clarification or add additional context in comments.

1 Comment

can u just give me a solution(i.e how to loop)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.