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/field_orderer.php4
<? class field_orderer { var $parser; var $new_fields; var $dialects; var $types; var $data; var $out; var $cur_refs; function fields_orderer() { $this->new_fields = array(); $this->dialects = array(); $this->types = array(); $this->xml = ""; $this->data = ""; } function rewrite($field, $value) { $new_field = $this->new_fields[$field]; $dialect = $this->dialects[$field]; $type = $this->types[$field]; $s = "\\$new_field $value\n"; $s .= "\\".$new_field."_t $type \n"; $s .= "\\".$new_field."_d $dialect\n"; return $s; } function startHandler($xp,$element,$attribs) { $element = strtolower($element); if($element == "refgroup") { $this->cur_refs = array(); } } function endHandler($xp,$element) { $element = strtolower($element); if($element != "refgroup") { if(array_key_exists($element,$this->new_fields)) { $s = $this->rewrite($element,$this->data); $this->cur_refs[$this->new_fields[$element]][] = $s; } else { if($this->data != "") { fwrite($this->out,"\\$element $this->data\n"); } } } else { foreach($this->new_fields as $new_field) { foreach($this->cur_refs[$new_field] as $x_ref) { fwrite($this->out,$x_ref); } unset($this->cur_refs[$new_field]); $this->cur_refs[$new_field] = array(); } fwrite($this->out,"\n"); } $this->data = ""; } function cDataHandler($xp,$data) { $data = trim($data); if($data != "") { $data = ereg_replace("&","&",$data); $data = ereg_replace("<","<",$data); $data = ereg_replace(">",">",$data); //$data = utf8_encode($data); $this->data .= $data; } } function get_fields($fields_file) { $in = fopen($fields_file,"r"); while($line = fgets($in)) { $line = trim($line); if($line == "") { break; } $vals = explode(" = ",$line); $new_field = $vals[0]; $field = $vals[1]; $dialect = $vals[2]; $this->new_fields[$field] = $new_field; $this->dialects[$field] = $dialect; } while($line = fgets($in)) { $line = trim($line); $vals = explode(" = ",$line); $fields = explode(",",$vals[0]); foreach($fields as $field) { $this->types[$field] = $vals[1]; } } asort($this->new_fields); } function get_reordered_shoebox($xml, $new_shoebox_name, $fields_file) { $this->out = fopen($new_shoebox_name,"w"); $this->get_fields($fields_file); $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"); $in = fopen($xml,"r"); while($line = fgets($in)) { xml_parse($this->parser,$line,false); } fclose($this->out); fclose($in); } } $fo = new field_orderer(); $fo->get_reordered_shoebox("ActiveNahuatl_2005_august_penult.xml","reordered.txt","field conversion.txt"); ?>