Javascript jQuery使用.nextAll()背靠背显示相邻的XML同级节点

Javascript jQuery使用.nextAll()背靠背显示相邻的XML同级节点,javascript,jquery,xml,Javascript,Jquery,Xml,我有以下XML: <building> <id>1</id> <name>Annex</name> <rooms> <room> <number>100</number> <type>conference room</type> <capacity&

我有以下XML:

<building>
    <id>1</id>
    <name>Annex</name>
    <rooms>
        <room>
            <number>100</number>
            <type>conference room</type>
            <capacity>4</capacity>
        </room>
        <room>
            <number>203</number>
            <type>computer lab</type>
            <capacity>30</capacity>
        </room>
    </rooms>
</building>

尽管如此,我真正关心的主要问题是如何声明多个语句;由于我只能显示其中一个,为什么不能同时声明这两个:
$(this).nextAll().eq(-1).appendTo($div)
和this:
$(this).nextAll().eq(0).appendTo($div)背靠背?

我找到了解决方案,但是我仍然不完全理解前面的语句为什么不起作用。不管怎样,我要做的是:

// Declare each node in its on HTML tag.
$('<h4>', { text: $(this).nextAll().eq(0).text(), class: 'roomText' }).appendTo($div);
$('<h4>', { text: $(this).nextAll().eq(1).text(), class: 'roomText' }).appendTo($div);
//在其on HTML标记中声明每个节点。
$('',{text:$(this.nextAll().eq(0.text(),class:'roomText'}).appendTo($div);
$('',{text:$(this.nextAll().eq(1.text(),class:'roomText'}).appendTo($div);

如果有人能解释一下逻辑,那就太好了。

是的,在这个解决方案中,但不是在您的原始代码中。您正在/正在将XML元素附加到HTML文档中,这是不应该做的。@RoToRa感谢您指出这一点
// Declare each node in its on HTML tag.
$('<h4>', { text: $(this).nextAll().eq(0).text(), class: 'roomText' }).appendTo($div);
$('<h4>', { text: $(this).nextAll().eq(1).text(), class: 'roomText' }).appendTo($div);