Tryag File Manager
Home
-
Turbo Force
Current Path :
/
home
/
cluster1
/
data
/
bu01
/
1121861
/
html
/
jlex
/
php4
/
Upload File :
New :
File
Dir
/home/cluster1/data/bu01/1121861/html/jlex/php4/schema_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 program provides this function as Jonathan Amiths database has around 100 fields at the root node. This avoids the hassle of having to write every field in the schema. The schema file is then rewritten to include the children of the root node. */ include_once("group.php4"); include_once("fields_loader.php4"); class schema_loader { var $parser; var $cur_group; var $ids; var $find_fields; var $get_field; var $data; var $id_field; var $group_fields; function schema_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"); $this->cur_group = false; $this->find_fields = false; $this->group_fields = array(); } function startHandler($xp, $element, $attribs) { $element = strtolower($element); //If the element is a 'group' element, we will create a new group belonging to the current group. if($element == "group") { $name = $attribs["NAME"]; //Initially, the current group is set to false. if(!$this->cur_group) { $parent = false; //$this->cur_group = new group($name,&$this->ids,$parent); } else { //Note: we set the parent to reference the current group. If you do not use the '&', PHP4 //clones the copy of the object. $parent = &$this->cur_group; unset($this->cur_group); } //echo "moving down from <B>".$this->cur_group->name."</B> to"; //Check to see if the user would prefer for the program to find the fields of the current group 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); unset($parent); //echo " <B>".$this->cur_group->name."</B><BR>"; } //If the element is a field element, we add the field to the current group 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($element == "group") { //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); if(!ereg("<",$hierarchy_xml)) { $in = fopen($hierarchy_xml,"r"); $xml = ""; while($line = fgets($in)) { $xml .= ereg_replace("&","&",$line); } } else { $xml = $hierarchy_xml; } $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; } xml_parser_free($this->parser); return $this->cur_group; } function write_schema($filename) { $out = fopen($filename,"w"); fwrite($out,$this->cur_group->structure_to_xml()); fclose($out); } } /* $sl = new schema_loader(); $refgroup = $sl->create_group_structure("../nahuatl/schema.xml",""); $fields = $refgroup->get_field_names(); foreach($fields as $field) { echo $field."\n"; } */ ?>