jQuery-遍历所有xml标签 [英] Jquery - iterate through all xml tags
本文介绍了jQuery-遍历所有xml标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何遍历xml中的所有标签
how to loop over all tags in a xml
我有一个php可以生成下一个类似xml的
i have a php that generates xmls like the next one
<register>
<name>peter</name>
<age>12</age>
</register>
<register>
<name>mary</name>
<age>20</age>
</register>
所以我收到了这个xml(效果很好)
so i receive this xml (this works fine)
$.ajax({success: function(xml) {
$(xml).find('register').each (function()
{
alert($(this).find('name').text()) // works fine, shows peter then mary on the next loop of "each"
// But if i dont know the tag names (name,age) for each register ?
// Something like
$(this).nodes().each .... //
alert($(this).tagName); // i wanna show "name" & "age", how can i get the tag names inside each register in my xml sample tree?
});
}});
推荐答案
您将要查看children()
函数等.有关功能的更多信息,请参见 jQuery遍历文档.
You'll want to look at the children()
function, among others. See the jQuery traversal documentation for more info on the functions.
这篇关于jQuery-遍历所有xml标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文