2015-08-31 41 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() ; 

});