XML.prototype.setChildren = function()

in asdoc/XML.js [2677:2729]


XML.prototype.setChildren = function(value) {
  var /** @type {number} */ len = 0;
  var /** @type {number} */ i = 0;
  //var /** @type {number} */ i = 0;
  //var /** @type {number} */ len = 0;
  var /** @type {XML} */ chld;
  if (org.apache.royale.utils.Language.is(value, XML)) {
    var /** @type {XMLList} */ list = new XMLList();
    list.setChild(0, value);
    value = list;
  }
  if (org.apache.royale.utils.Language.is(value, XMLList)) {
    var /** @type {XMLList} */ chldrn = this.children();
    var /** @type {number} */ childIdx = (chldrn.length() - 1) >> 0;
    if (chldrn.length())
      childIdx = (chldrn[0].childIndex()) >> 0;
    len = (chldrn.length() - 1) >> 0;
    var /** @type {XML} */ origFirstChild = null;
    this.XML__internalSuppressNotify = true;
    for (i = len; i >= 0; i--) {
      this.removeChild(chldrn[i]);
      if (i > 0) {
        this.XML__internalSuppressNotify = false;
        this.xml$_notify("nodeRemoved", this, chldrn[i], null);
        this.XML__internalSuppressNotify = true;
      } else {
        origFirstChild = chldrn[i];
      }
    }
    this.XML__internalSuppressNotify = false;
    var /** @type {XML} */ curChild = this.XML_getChildren()[childIdx];
    var /** @type {XML} */ firstChild = null;
    len = (value.length()) >> 0;
    this.XML__internalSuppressNotify = true;
    for (i = 0; i < len; i++) {
      chld = value[i];
      if (!firstChild)
        firstChild = chld;
      if (!curChild) {
        curChild = chld;
        this.appendChild(chld);
      } else {
        this.insertChildAfter(curChild, chld);
        curChild = chld;
      }
    }
    this.XML__internalSuppressNotify = false;
    if (len > 0) {
      this.xml$_notify(origFirstChild ? "nodeChanged" : "nodeAdded", this, firstChild, origFirstChild);
    }
  }
  return this;
};