コード例 #1
0
ファイル: xml.php プロジェクト: kaz0636/openflp
 /**
  * Parses and creates XML nodes from the __rawData property.
  *
  * @return boolean Success
  * @access public
  * @see load()
  */
 function parse()
 {
     $this->header = trim(str_replace(a('<' . '?', '?' . '>'), a('', ''), substr(trim($this->__rawData), 0, strpos($this->__rawData, "\n"))));
     xml_parse_into_struct($this->__parser, $this->__rawData, $vals);
     $xml = new XMLNode();
     $count = count($vals);
     for ($i = 0; $i < $count; $i++) {
         $data = $vals[$i];
         switch ($data['type']) {
             case "open":
                 $tmpXML = new XMLNode();
                 $tmpXML->name = $data['tag'];
                 if (isset($data['value'])) {
                     $tmpXML->value = $data['value'];
                 }
                 if (isset($data['attributes'])) {
                     $tmpXML->attributes = $data['attributes'];
                 }
                 $tmpXML->setParent($xml);
                 $ct = count($xml->children);
                 $xml->children[$ct] = $tmpXML;
                 $xml =& $xml->children[$ct];
                 break;
             case "close":
                 $xml =& $xml->parent();
                 break;
             case "complete":
                 $tmpXML = new XMLNode();
                 $tmpXML->name = $data['tag'];
                 if (isset($data['value'])) {
                     $tmpXML->value = $data['value'];
                 }
                 if (isset($data['attributes'])) {
                     $tmpXML->attributes = $data['attributes'];
                 }
                 $tmpXML->__parent =& $xml;
                 $xml->children[] = $tmpXML;
                 break;
             case 'cdata':
                 if (is_string($xml->value)) {
                     $xml->value = a($xml->value, $data['value']);
                 } else {
                     $xml->value[] = $data['value'];
                 }
                 break;
         }
     }
     $this->children =& $xml->children;
     return true;
 }