[英]XML parsing with Jquery
<resultGroups>
<subGroups>
<results> </results>
<name></name>
</subGroups>
<subGroups>
<results> </results>
<name></name>
</subGroups>
<name>myname</name>
</resultGroups>
<resultGroups>
<subGroups>
<results> </results>
<results> </results>
<name></name>
</subGroups>
<subGroups>
<results> </results>
<results> </results>
<name></name>
</subGroups>
<name>othername</name>
</resultGroups>
how can i select the name tag of first resultGroup only using jquery??? 如何才能使用jquery ???选择第一个resultGroup的名称标签?
$.ajax({
url: "result.xml",
dataType: "xml",
success: function(data){
// Parsing happens here
}
});
To parse the document we have two main functions available "each" and "find". 为了解析文档,我们有两个主要功能:“each”和“find”。 The function "each" will loop over all the tags with a specific name, the function "find" will search for a certain tag.
函数“each”将循环遍历具有特定名称的所有标记,函数“find”将搜索某个标记。
$(data).find("resultGroup").each(function() {
alert("found a resultGroup");
});
$(data).find("resultGroup").each(function() {
alert($(this).find("subgroups").text());
});
$(data).find("subgroups").each(function() {
alert($(this).attr("result"));
});
$('resultGroup subGroups name')[0]
If you want to be more specific, you could split the selection and fetch the first array index for each: 如果您想更具体,可以拆分选择并获取每个的第一个数组索引:
$('name', $('subGroups', $('resultGroup')[0])[0])
... I think. ... 我认为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.