using javascript to parse XML string -
i have xml file in following format,
in data1 array, getting first 'webportal:highresurl' value, not values (i.e 'webportal:highresurl' contains 2 values). 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"); (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();
because getting 1 value <webportal:highresurl>
item.getelementsbytagname("webportal:highresurl").item(0).text
the above line returns text of first <webportal:highresurl>
. seems static 1 make on loop 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, }); }}
Comments
Post a Comment