コード例 #1
0
 /**
  * Inserts a node to the childNodes list of the current node
  * @param Object The node to be inserted
  * @param Object The node before which the insertion is to occur 
  * @return Object The inserted node
  */
 function &insertBefore(&$newChild, &$refChild)
 {
     $type = $newChild->nodeType;
     if ($type == DOMIT_ELEMENT_NODE) {
         if ($this->documentElement == null) {
             parent::insertBefore($newChild);
             $this->setDocumentElement($newChild);
         } else {
             //error thrown if documentElement already exists!
             DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR, 'Cannot have more than one root node (documentElement) in a DOMIT_Document.');
         }
     } else {
         DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR, 'Cannot insert a node of type ' . get_class($newChild) . ' to a DOMIT_Document.');
     }
     return $newChild;
 }
コード例 #2
0
 /**
  * Inserts a node to the childNodes list of the current node
  * @param Object The node to be inserted
  * @param Object The node before which the insertion is to occur 
  * @return Object The inserted node
  */
 function &insertBefore(&$newChild, &$refChild)
 {
     $type = $newChild->nodeType;
     if ($this->nodeType == DOMIT_DOCUMENT_FRAGMENT_NODE) {
         $total = $newChild->childCount;
         for ($i = 0; $i < $total; $i++) {
             $currChild =& $newChild->childNodes[$i];
             $this->insertBefore($currChild, $refChild);
         }
     } else {
         if ($type == DOMIT_ELEMENT_NODE) {
             if ($this->documentElement == null) {
                 parent::insertBefore($newChild);
                 $this->setDocumentElement($newChild);
             } else {
                 //error thrown if documentElement already exists!
                 DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR, 'Cannot have more than one root node (documentElement) in a DOMIT_Document.');
             }
         } else {
             if ($type == DOMIT_PROCESSING_INSTRUCTION_NODE) {
                 parent::insertBefore($newChild);
             } else {
                 if ($type == DOMIT_DOCUMENT_TYPE_NODE) {
                     if ($this->doctype == null) {
                         parent::insertBefore($newChild);
                     } else {
                         DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR, 'Cannot have more than one doctype node in a DOMIT_Document.');
                     }
                 } else {
                     DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR, 'Cannot insert a node of type ' . get_class($newChild) . ' to a DOMIT_Document.');
                 }
             }
         }
     }
     return $newChild;
 }