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?

1 of 2 people (50%) answered Yes
Recently 1 of 2 people (50%) answered Yes

Entry

How do I use the method parent?
How do I use the method parent?

Apr 16th, 2005 23:01
Martin Honnen,


The method parent takes no argument and returns the common parent of all
XML objects in this XMLList if all those objects have the same parent,
otherwise undefined is returned.
Here are some examples:
  // common parent
  var gods = <gods>
    <god>Kibo</god>
    <god>Xibo</god>
  </gods>;
  var godList = gods.god;
  alert(godList.parent().name()); // shows 'gods'
  // if all XML objects have parent as null they do have the same
  // parent value thus calling parent on the XMLList returns null
  var godList = <>
    <god>Kibo</god>
    <god>Xibo</god>
  </>;
  alert(godList.parent()); // shows 'null'
  // different parents for the XML objects in the XMLList
  var html = <html>
    <head>
      <title>Kibology</title>
    </head>
    <body>
      <h1>Kibology</h1>
    </body>
  </html>;
  var xmlList = html..*;
  alert(xmlList.parent()); // shows 'undefined'