2015-08-31 39 views
0

我有ajax调用xml respnse。我想迭代它。 以下是我在SoaUi的xml输出。jquery迭代xml响应

我想如下输出响应:

 
50 Water St Oakland USA 
101 Emerall New York USA 
Sea Point CA USA 

请帮我写jQuery的响应。

编辑: 这是我在XML响应:

<ns3:Row> 
<ns3:AddressLine1>50 Water St</ns3:AddressLine1> 
<ns3:City>Oakland</ns3:City> 
<ns3:Country>USA</ns3:Country> 
</ns3:Row> 
<ns3:Row> 
<ns3:AddressLine1>101 Emerall</ns3:AddressLine1> 
<ns3:City>New York</ns3:City> 
<ns3:Country>USA</ns3:Country> 
</ns3:Row> 
<ns3:Row> 
<ns3:AddressLine1>Sea Point</ns3:AddressLine1> 
<ns3:City>CA</ns3:City> 
<ns3:Country>USA</ns3:Country> 
</ns3:Row> 
+1

请更新您的问题与评论信息。 – sakura

回答

0

你可以得到的信息需要通过元素循环和存储在一个字符串或任何你找到合适的信息。

一种解决方案(混合jQuery和普通的JavaScript)可以如下:

$(f).each(function (ind, el) { 
    var line = ''; 
    $(el).children().each(function (ind, nod) { 
     line += nod.childNodes[0].nodeValue + ' '; 
    }); 
    console.log(line.slice(0, -1)); 
}); 

变量 'F' 包含从服务器检索的XML字符串。

您可以在fiddle(打开开发者控制台查看打印结果)中对其进行测试。

希望它有帮助。

0

解决方法就在这里。

var geoCompAddress; 


$(data).find('ns3\\:Row').each(function() { 

geoCompAddress = $(this).find('ns3\\:AddressLine1').text()+ ',' + $(this).find('ns3\\:City').text()+ ',' + $(this).find('ns3\\:Country').text() ; 

});