XML.prototype.XML_appendChildInternal = function()

in asdoc/XML.js [1124:1195]


XML.prototype.XML_appendChildInternal = function(child, isTextSet) {
  isTextSet = typeof isTextSet !== 'undefined' ? isTextSet : false;
  var /** @type {number} */ alreadyPresent = 0;
  var /** @type {number} */ i = 0;
  var /** @type {string} */ kind;
  //var /** @type {number} */ alreadyPresent = 0;
  var /** @type {Array} */ children = this.XML_getChildren();
  var /** @type {boolean} */ isAttribute;
  if (org.apache.royale.utils.Language.is(child, XMLList)) {
    var /** @type {number} */ len = (child.length()) >> 0;
    var /** @type {number} */ oldChildrenLength = this.childrenLength();
    //var /** @type {number} */ i = 0;
    for (i = 0; i < len; i++) {
      var /** @type {XML} */ childItem = child[i];
      isAttribute = false;
      kind = childItem.getNodeRef();
      if (kind == XML.ATTRIBUTE) {
        var /** @type {string} */ name = childItem.localName();
        var /** @type {string} */ content = '<' + name + '>' + childItem.toString() + '</' + name + '>';
        childItem = new XML(content);
        isAttribute = true;
      } else {
        alreadyPresent = (children.indexOf(childItem)) >> 0;
        if (alreadyPresent != -1)
          children.splice(alreadyPresent, 1);
      }
      childItem.setParent(this, true);
      children.push(childItem);
    }
    if (this.XML__notification || (XML.recursiveNotify && this.XML__parent)) {
      for (i = 0; i < len; i++) {
        var /** @type {XML} */ originalChildItem = child[i];
        isAttribute = false;
        kind = originalChildItem.getNodeRef();
        if (kind == XML.ATTRIBUTE) {
          isAttribute = true;
        }
        var /** @type {XML} */ finalChildItem = children[oldChildrenLength + i];
        if (isAttribute)
          this.xml$_notify("attributeAdded", this, finalChildItem.name().toString(), finalChildItem.getValue());
        else
          this.xml$_notify("nodeAdded", this, finalChildItem, null);
      }
    }
  } else {
    org.apache.royale.debugging.assertType(child, XML, "Type must be XML");
    isAttribute = false;
    kind = org.apache.royale.utils.Language.string(child.getNodeRef());
    if (kind == XML.ATTRIBUTE) {
      child = new XML(child.toString());
      isAttribute = true;
    } else {
      alreadyPresent = (children.indexOf(child)) >> 0;
      if (alreadyPresent != -1)
        children.splice(alreadyPresent, 1);
    }
    child.setParent(this);
    children.push(child);
    if (isAttribute) {
      if (isTextSet) {
        this.xml$_notify("textSet", child, child.getValue(), null);
      }
      this.xml$_notify("attributeAdded", this, child.name().toString(), child.getValue());
    } else if (isTextSet) {
      var /** @type {XML} */ childValueNode = (child._children ? child._children[0] : child);
      this.xml$_notify("textSet", childValueNode, childValueNode.getValue(), null);
      this.xml$_notify("nodeAdded", childValueNode.XML__parent, childValueNode, null);
    }
    else
      this.xml$_notify("nodeAdded", this, child, null);
  }
};