コード例 #1
0
 /**
  * Appends a node to the childNodes list of the current node
  * @param Object The node to be appended 
  * @return Object The appended node
  */
 function &appendChild(&$node)
 {
     if ($node->nodeType == DOMIT_ELEMENT_NODE) {
         if ($this->documentElement == null) {
             parent::appendChild($node);
             $this->setDocumentElement($node);
         } 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 add a node of type ' . get_class($node) . ' to a DOMIT_Document.');
     }
     return $node;
 }
コード例 #2
0
 /**
  * Appends a node to the childNodes list of the current node
  * @param Object The node to be appended 
  * @return Object The appended node
  */
 function &appendChild(&$node)
 {
     switch ($node->nodeType) {
         case DOMIT_ELEMENT_NODE:
             if ($this->documentElement == null) {
                 parent::appendChild($node);
                 $this->setDocumentElement($node);
             } 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.');
             }
             break;
         case DOMIT_PROCESSING_INSTRUCTION_NODE:
         case DOMIT_COMMENT_NODE:
             parent::appendChild($node);
             break;
         case DOMIT_DOCUMENT_TYPE_NODE:
             if ($this->doctype == null) {
                 parent::appendChild($node);
             } else {
                 DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR, 'Cannot have more than one doctype node in a DOMIT_Document.');
             }
             break;
         case DOMIT_DOCUMENT_FRAGMENT_NODE:
             $total = $node->childCount;
             for ($i = 0; $i < $total; $i++) {
                 $currChild =& $node->childNodes[$i];
                 $this->appendChild($currChild);
             }
             break;
         default:
             DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR, 'Cannot add a node of type ' . get_class($node) . ' to a DOMIT_Document.');
     }
     return $node;
 }