faqts : Computers : Programming : Languages : JavaScript : XML : E4X (ECMAScript for XML) : XML 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 hasComplexContent?
How do I use the method hasComplexContent?

Apr 10th, 2005 04:09
Martin Honnen,


The method hasComplexContent takes no argument. It returns false for XML
objects of node kind text, attribute, comment, and processing
instruction while for XML objects of node kind element it checks whether
the element has at least one child element and returns true then and
false otherwise.
Here are some examples:
  var gods = <gods>
    <god>
      <name>Kibo</name>
    </god>
    <devil>Xibo</devil>
  </gods>;
  alert(gods.hasComplexContent()); // shows 'true'
  alert(gods.god[0].hasComplexContent()); // shows 'true'
  alert(gods.devil[0].hasComplexContent()); // shows 'false'
  alert(gods.god[0].name[0].hasComplexContent()); // shows 'false'
  var xmlTextObject = new XML('Kibology for all.');
  alert(xmlTextObject.hasComplexContent()); // shows 'false'
  var xmlAttribute = <god name="Kibo" />.@name;
  alert(xmlAttribute.hasComplexContent()); // shows 'false'
  XML.ignoreComments = false;
  var xmlComment = <!-- Kibology for all. -->;
  alert(xmlComment.hasComplexContent()); // shows 'false'
  XML.ignoreProcessingInstructions = false;
  var xmlProcessingInstruction = <?process Kibology="on"?>;
  alert(xmlProcessingInstruction.hasComplexContent()); // shows 'false'