在Jquery中解析XML [英] XML parsing in Jquery
问题描述
我有一个XML文件,其中有四个< resutGroups>
标签:
I have an XML file which has four <resutGroups>
tag:
<resultGroups>
<subGroups>
<name> </name>
</subGroups>
<name> </name>
</resultGroups>
每个< resultGroup>
code>< subGroups> ,每个< subGroups>
有< name>
标签。
each <resultGroup>
has several <subGroups>
and each <subGroups>
has <name>
tag.
我只想选择< resultGroups>
的名称标签
$(xml).find("resultGroups").each(function() {
alert( $(this).find("name").text() );
}
上面的代码,它返回< resultgroups>
和< subGroups>
中的所有名称。
When I use the above code it returns all the names inside the <resultgroups>
and <subGroups>
.
如何只选择< resultGroups> $中的一个
< name>
c $ c>标签?
How can I select only one <name>
which is in the <resultGroups>
tag?
推荐答案
您有以下几种选择:
var xml = $(xml);
$('resultGroups > name', xml).each(function() {
alert($(this).text());
});
=http://docs.jquery.com/Selectors/child#parentchild =noreferrer>直接后裔选择器。您也可以使用 儿童
同样的事情:
This uses the direct descendant selector. You could also use children
, which does the same thing:
$('resultGroups', xml).children('name').each(function() {
alert($(this).text());
});
这篇关于在Jquery中解析XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!