【发布时间】:2015-04-06 07:58:16
【问题描述】:
我正在尝试解析来自 jQuery 的 GET 请求的 XML 响应。 问题似乎是我感兴趣的 XML 元素的类型。
请告诉我如何解析这个。
<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:app="http://purl.org/atom/app#"
xmlns:yt="http://gdata.youtube.com/schemas/2007" xmlns:gd="http://schemas.google.com/g/2005"
xmlns:media="http://search.yahoo.com/mrss/">
<id>http://gdata.youtube.com/feeds/api/videos/VVoO9cdk5Eo</id>
<published>2015-04-03T18:30:00.000Z</published>
<updated>2015-04-06T02:11:57.000Z</updated>
<gd:rating average="4.9371624" max="5" min="1" numRaters="2037"
rel="http://schemas.google.com/g/2005#overall" />
<yt:statistics favoriteCount="0" viewCount="148847" />
使用我的代码,我可以成功检索“已发布”之类的内容。但我需要解析 'gd:rating'
$(document).ready(function(){
$("#mybutton").click(function(){
$.ajax({
type: "GET",
dataType: "xml",
url: "https://gdata.youtube.com/feeds/api/videos/VVoO9cdk5Eo?v=1",
success: function(response){
console.log("Success");
var rating = $(response).find('published').first().text();
alert("#" + rating);
}
});
});
});
【问题讨论】: