//parse the XML string (wherever it comes from), then find all the `item` tags and select their child `description` tags, now we have all the `description` tags in your XML document
var $xml_parsed = $($.parseXML(xml_string)).find('item').children('description');
//now iterate through the `description` tags and find the `#dangericon` element within each
for (var i = 0, len = $xml_parsed.length; i < len; i++) {
//to find an element we must create a jQuery object from the text of this `description` tag and then we can use `.find()` to search for the desired element
var tmp = $($xml_parsed.eq(i).text()).find('#dangericon');
//you can do what you want with the element now, it is saved in the `tmp` variable
}
這裏是一個演示:http://jsfiddle.net/pdT8S/
我假定這是被在同一個域中進行,如果是這樣的話,那麼你就不需要惹jsonp
但如果你是在跨域調用XML文檔時,您需要查看jsonp
請求(只要遠程服務器設置正確,就可以輕鬆使用jQuery進行請求)。
P.S.我是Truckee的本地人,並且願意幫助您處理任何以滑雪爲中心的網站。
你想用小提琴演奏什麼? XML在哪裏? – 2011-12-29 19:47:01
您通常無法通過Javascript加載XML(例如,通過$ .ajax()),除非該提要在您的域中。不過,您可以在服務器上加載並解析它。你沒有訪問服務器端編碼嗎? – 2011-12-29 19:49:53
「...由於格式不正確的XML而無法正常工作」 - 是否解決這個問題,以確保XML格式正確?或者你不控制XML?如果您無法控制,那可能意味着XML來自另一個域?在這種情況下,由於安全限制,JavaScript可能無法實現。 – 2011-12-29 19:51:16