Tryag File Manager
Home
-
Turbo Force
Current Path :
/
home
/
cluster1
/
data
/
bu01
/
1121861
/
html
/
old_jlex_versions
/
php
/
Upload File :
New :
File
Dir
/home/cluster1/data/bu01/1121861/html/old_jlex_versions/php/hierarchy_loader.php4
<? /* This class reads an xml file describing the schema of an xml file and creates an group data structure representing that schema. It allows the user the option of either providing a list of the children of the root node or letting the program automatically search for them. The schema file is then rewritten to include the children of the root node. */ include_once("group.php4"); include_once("fields_loader.php4"); class hierarchy_loader { var $parser; var $cur_group = false; var $ids; var $find_fields = false; var $get_field; var $data; var $id_field; var $group_fields = array(); var $cur_count; function hierarchy_loader() { $this->parser = xml_parser_create(); xml_set_object($this->parser,$this); xml_set_element_handler($this->parser,"startHandler","endHandler"); xml_set_character_data_handler($this->parser,"cDataHandler"); } function startHandler($xp, $element, $attribs) { $element = strtolower($element); if(eregi("group",$element)) { $name = $attribs["NAME"]; if(!$this->cur_group) { $parent = false; $this->cur_group = new group($name,&$this->ids,$parent); } else { $parent = &$this->cur_group; unset($this->cur_group); } //echo "moving down from <B>".$this->cur_group->name."</B> to"; if(array_key_exists("FIND_FIELDS",$attribs)) { $find_fields = trim($attribs["FIND_FIELDS"]); } else { $find_fields = "false"; } if($find_fields == "true") { $this->find_fields = true; $this->id_field = $name; } $this->ids[$element] = 1; $this->cur_group = new group($name,&$this->ids, $parent); //echo " <B>".$this->cur_group->name."</B><BR>"; } else { $this->get_field = true; $this->data = ""; if(array_key_exists("COUNT",$attribs)){ $this->count = trim($attribs["COUNT"]); } else { $this->count = 1; } } } function endHandler($xp, $element) { $element = strtolower($element); if(eregi("group",$element)) { //echo "moving up from <B>".$this->cur_group->name."</B> to"; $child = &$this->cur_group; if($child->parent === false) { //echo " the root <BR>"; } else { unset($this->cur_group); $this->cur_group = &$child->parent; $this->cur_group->add_group($child); //echo " <B>".$this->cur_group->name."</B><BR>"; } } else if($this->get_field) { $this->cur_group->add_field($this->data,$this->count); if($this->find_fields) { if(!in_array($this->data,$this->group_fields)) { $this->group_fields[$this->data] = $this->cur_group->name; } } $this->get_field = false; $this->count = 1; } } function cDataHandler($xp, $data) { if($this->get_field) { $this->data .= trim($data); } } function create_group_structure($hierarchy_xml,$lexicon_xml) { set_time_limit(1000); //$start = date("r")."<BR>"; $in = file($hierarchy_xml); $xml = ""; foreach($in as $line) { $xml .= ereg_replace("&","&",$line); } $good_parse = xml_parse($this->parser,$xml); if(!$good_parse) { echo "BAD PARSE: ".xml_get_current_line_number($this->parser)."<BR>"; } //echo $start; //echo date("r")."<BR>"; if($this->find_fields) { $fl = new fields_loader($lexicon_xml, $this->id_field,$this->group_fields); $fields = $fl->get_root_fields(); $this->cur_group->fields = $fields; $i = strpos($lexicon_xml,"."); $out_file = substr($lexicon_xml,0,$i)."_hierarchy.xml"; $out = fopen($out_file,"w"); fwrite($out,$this->cur_group->structure_to_xml()); fclose($out); } return $this->cur_group; } } ?>