Reputation: 41
I'm currently working with Javascript Rhino and E4X.
Is there a difference between using elements() and children() besides the possibility to use an additional argument in the elements method to get only elements with that name.
Example:
new XML(<x><a><q/></a><b/><c/></x>).children();
new XML(<x><a><q/></a><b/><c/></x>).elements();
Kind regards,
Aeonnex
Upvotes: 1
Views: 113
Reputation: 41
As Jaromanda X pointed out:
text nodes are children but not elements ... i.e. children include all elements and text nodes ... elements won't include text nodes – Jaromanda X
So in the following example there is a difference between the elements() and children() method:
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/>
*/
Upvotes: 1