コード例 #1
0
 /**
  * Replaces a node with another
  * @param Object The new node
  * @param Object The old node
  * @return Object The new node
  */
 function &replaceChild(&$newChild, &$oldChild)
 {
     if ($this->documentElement != null && $oldChild->uid == $this->documentElement->uid) {
         if ($node->nodeType == DOMIT_ELEMENT_NODE) {
             //replace documentElement with new node
             $this->setDocumentElement($newChild);
         } else {
             DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR, 'Cannot replace Document Element with a node of class ' . get_class($newChild));
         }
     } else {
         if ($node->nodeType == DOMIT_ELEMENT_NODE) {
             if ($this->documentElement != null) {
                 DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR, 'Cannot have more than one root node (documentElement) in a DOMIT_Document.');
             } else {
                 parent::replaceChild($newChild, $oldChild);
             }
         } else {
             DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR, 'Nodes of class ' . get_class($newChild) . ' cannot be children of a DOMIT_Document.');
         }
     }
     return $newChild;
 }
コード例 #2
0
 /**
  * Replaces a node with another
  * @param Object The new node
  * @param Object The old node
  * @return Object The new node
  */
 function &replaceChild(&$newChild, &$oldChild)
 {
     if ($this->nodeType == DOMIT_DOCUMENT_FRAGMENT_NODE) {
         $total = $newChild->childCount;
         if ($total > 0) {
             $newRef =& $newChild->lastChild;
             $this->replaceChild($newRef, $oldChild);
             for ($i = 0; $i < $total - 1; $i++) {
                 $currChild =& $newChild->childNodes[$i];
                 parent::insertBefore($currChild, $newRef);
             }
         }
     } else {
         if ($this->documentElement != null && $oldChild->uid == $this->documentElement->uid) {
             if ($newChild->nodeType == DOMIT_ELEMENT_NODE) {
                 //replace documentElement with new node
                 $this->setDocumentElement($newChild);
             } else {
                 DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR, 'Cannot replace Document Element with a node of class ' . get_class($newChild));
             }
         } else {
             switch ($newChild->nodeType) {
                 case DOMIT_ELEMENT_NODE:
                     if ($this->documentElement != null) {
                         DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR, 'Cannot have more than one root node (documentElement) in a DOMIT_Document.');
                     } else {
                         parent::replaceChild($newChild, $oldChild);
                     }
                     break;
                 case DOMIT_PROCESSING_INSTRUCTION_NODE:
                 case DOMIT_COMMENT_NODE:
                     parent::replaceChild($newChild, $oldChild);
                     break;
                 case DOMIT_DOCUMENT_TYPE_NODE:
                     if ($this->doctype != null) {
                         if ($this->doctype->uid == $oldchild->uid) {
                             parent::replaceChild($newChild, $oldChild);
                         } else {
                             DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR, 'Cannot have more than one doctype node in a DOMIT_Document.');
                         }
                     } else {
                         parent::replaceChild($newChild, $oldChild);
                     }
                     break;
                 default:
                     DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR, 'Nodes of class ' . get_class($newChild) . ' cannot be children of a DOMIT_Document.');
             }
         }
     }
     return $newChild;
 }