我目前正在使用Javascript Rhino和E4X
我目前正在使用Javascript Rhino和E4X
使用elements((和children((之间除了可以在elements方法中使用额外的参数来只获取具有该名称的元素之外,还有区别吗。示例:
new XML(<x><a><q/></a><b/><c/></x>).children();
new XML(<x><a><q/></a><b/><c/></x>).elements();
问候,
Aeonnex
正如Jaromanda X所指出的:
文本节点是子节点,但不是元素。。。即子节点包括所有元素和文本节点。。。元素将不包括文本节点–Jaromanda X
因此,在以下示例中,elements((和children((方法之间存在差异:
new XML(<x><a><q/></a><b/>abc<c/></x>).children()
/*
<a><q/></a>
<b/>
abc
<c/>
*/
new XML(<x><a><q/></a><b/>abc<c/></x>).elements()
/*
<a><q/></a>
<b/>
<c/>
*/