根据下面的示例xml,我们需要以相同的顺序解析文本。我使用find()方法获取节点的值,但所有段落组合在一起,所有多媒体组合在一起。
如何获得如下所示的预期输出 任何帮助将不胜感激
<section ID="warn">
<title>WARNINGS</title>
<text>
<paragraph>first sample text</paragraph>
<multimedia>sample Media1</multimedia>
<paragraph>Second sample text</paragraph>
<paragraph>Third sample text</paragraph>
<paragraph>Fourth sample text</paragraph>
<multimedia>sample Media2</multimedia>
<paragraph>Fifth sample text</paragraph>
</text>
</component>
Expected output should be like below
WARNINGS
first sample text
sample Media1
Second sample text
Third sample text
Fourth sample text
sample Media2
答案 0 :(得分:0)
你可以使用,
var nodes = $("section *").filter(function() {
return $(this).children().length == 0;
});
nodes.each(function() {
console.log($(this).text());
});