jQuery parsing XML: get an element with a specific attribute
var xml='<cards>\
<card id="3">\
<name lang="es"></name>\
<description lang="es"></description>\
<name lang="en"></name>\
<description lang="en"></description>\
</card></cards>';
and the jquery part
$(xml).find('Card').each(function(i,j)
{
console.log($(j).attr("id"));
console.log($(j).find("name").attr("lang"));
});
http://www.jsfiddle.net/VZjmV/6/
To answer the specific questions, "How can I pass this argument to function parserCardsXml(xml)?"
function loadCards(lang)
{
$.ajax({
type: "GET",
url: 'data/english.xml',
dataType: "xml",
success: function (xml) { parseCardsXml(xml, lang); }
});
}
And, "How can I get name and description with a specific attribute?"
function parseCardsXml(xml, lang)
{
var $xml = $(xml),
name = $xml.find('name[lang="' + lang + '"]').text(),
desc = $xml.find('desc[lang="' + lang + '"]').text();
}