javascriptrhinoe4x

What's the difference in E4X between the elements() and children() method




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


Solution

  • 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/>
    */