//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