我将iTunes资料库导出到xml文件,它看起来像这样:
<key>725</key>
<dict>
<key>Track ID</key><integer>725</integer>
<key>Name</key><string>Sandstorm</string>
<key>Artist</key><string>Daro</string>
<key>Album</key><string>Gunther D</string>
<key>Genre</key><string>Dance</string>
<key>Kind</key><string>MPEG-audiobestand</string>
<key>Size</key><integer>6937997</integer>
<key>Total Time</key><integer>223451</integer>
<key>Track Number</key><integer>3</integer>
<key>Year</key><integer>2013</integer>
<key>Library Folder Count</key><integer>1</integer>
</dict>
我做了我的ajax调用来读出xml文件。但现在我想获得专辑密钥和字符串,但我不知道如何达到它。
$(document).ready(function(){
$.ajax({
url: "Bibliotheek.xml",
dataType: "xml",
success: function(data){
var $xml = $(data);
var $key = $xml.find('key').each(function(){
console.log($key);
});
}
});
});
现在它将我的所有密钥记录在我的控制台中,但我只想要相册密钥
答案 0 :(得分:0)
您可以过滤按键
$(document).ready(function(){
$.ajax({
url : "Bibliotheek.xml",
dataType : "xml",
success : function(data){
var album = $(data).find('key').filter(function() {
return $(this).text().indexOf('Album') != -1;
}).next('string').text();
}
});
});