faqts : Computers : Programming : Languages : JavaScript : XML : E4X (ECMAScript for XML) : XMLList objects

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

Entry

How do I use the method child?
How do I use the method child?

Apr 14th, 2005 03:57
Martin Honnen,


The method child takes one argument, the child property name to look
for, and calls the method child
(http://www.faqts.com/knowledge_base/view.phtml/aid/35366/fid/1784) of
each XML object in this XMLList object to return an XMLList with the
matching children in order.
[Note: while the method child exists you can use the shorter child
property accessors
  xmlList.childPropertyName
  xmlList['childPropertyName']
instead.]
Here are some examples using the method child:
  var godList = <>
    <god>
      <name>Kibo</name>
      <home>http://www.kibo.com/</home>
    </god>
    <god>
      <name>Xibo</name>
    </god>
  </>;
  alert(godList.child('name').length()); // shows 2
  alert(godList.child('home').length()); // shows 1
  alert(godList.child('*').length()); // shows 3
  // compare to (shorter) child property access
  alert(godList.name.length()); // shows 2
  alert(godList.home.length()); // shows 1
  alert(godList.*.length()); // shows 3