【发布时间】:2019-04-05 11:11:54
【问题描述】:
我在 XML 代码中有以下结构和
<drinks>
<soft>
<subject>
<soft>
<subject>
<brand-name></brand-name>
<subject>
<brand-name></brand-name>
</subject>
</subject>
<link></link>
<soft>
<nature>
<brand-name></brand-name>
<link></link>
</nature>
<info></info>
</drinks>
我需要确认<info> 是<drinks> 的最后一个孩子我不知道这样做...我在下面尝试
var $element = $xml.find("drinks").addBack("drinks");
alert($element.children().last().nodeName);
我还需要确认每个<subject> <brand-name> 是第一个孩子。我试试下面的代码
function check_first_child(parent, child, rule, error_type)
{
if(($xml.find(parent).length > 0))
{
var $parent = $xml.find(parent).addBack(parent);
$parent.children().first().each(function()
{
alert(this.nodeName);
});
}
}
但是上面的代码只找到了一次主题。我总共有两个主题。
【问题讨论】:
-
@trincot 你能指导我吗
标签: jquery ajax xml-parsing