コード例 #1
0
ファイル: xml.php プロジェクト: thu0ng91/jmc
 function _xml_get_children($vals, &$i)
 {
     $children = array();
     // CData section before children
     if (isset($vals[$i]['value'])) {
         $tmp = new XMLText();
         $tmp->nodeValue = $vals[$i]['value'];
         $tmp->nodeType = XML_TYPE_CDATA;
         $children[] = $tmp;
     }
     // Browse children
     $lastelm = '';
     $nChildren = count($vals);
     while (++$i < $nChildren) {
         switch ($vals[$i]['type']) {
             case 'cdata':
                 if ($lastelm != 'cdata') {
                     // New CData section
                     $tmp = new XMLText();
                     $tmp->nodeValue = $vals[$i]['value'];
                     $tmp->nodeType = XML_TYPE_CDATA;
                     $children[] = $tmp;
                 } else {
                     // Continuing last CData section
                     $children[count($children) - 1]->nodeValue .= $vals[$i]['value'];
                 }
                 break;
             case 'complete':
                 $tmp = new XMLNode();
                 $tmp->nodeName = $vals[$i]['tag'];
                 $tmp->attributes = isset($vals[$i]['attributes']) ? $vals[$i]['attributes'] : NULL;
                 if (isset($vals[$i]['value'])) {
                     $tmp->appendChild(XMLNode::createTextNode($vals[$i]['value']));
                 }
                 $tmp->parentNode = $this;
                 $children[] = $tmp;
                 break;
             case 'open':
                 $tmp = new XMLNode();
                 $tmp->nodeName = $vals[$i]['tag'];
                 $tmp->attributes = isset($vals[$i]['attributes']) ? $vals[$i]['attributes'] : NULL;
                 $tmp->parentNode = $this;
                 $tmp->childNodes = $tmp->_xml_get_children($vals, $i);
                 $children[] = $tmp;
                 break;
             case 'close':
                 $nThisChildren = count($children);
                 if ($nThisChildren > 1) {
                     for ($j = $nThisChildren - 2; $j >= 0; $j--) {
                         $children[$j]->nextSibling =& $children[$j + 1];
                     }
                     for ($j = 1; $j < $nThisChildren; $j++) {
                         $children[$j]->previousSibling =& $children[$j - 1];
                     }
                 }
                 $this->firstChild =& $children[0];
                 $this->lastChild =& $children[($nThisChildren - 1) % $nThisChildren];
                 return $children;
                 break;
         }
         $lastelm = $vals[$i]['type'];
     }
 }