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/fields_loader.php4
<? //include_once("group.php4"); class fields_loader { var $parser; var $main_fields = array(); var $group_fields; var $cur_entry_fields = array(); var $head_tag; var $count; var $xml_file; function fields_loader($xml_file, $head_tag,$group_fields) { $this->xml_file = $xml_file; $this->head_tag = $head_tag; $this->group_fields = $group_fields; $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) { //echo "START: $element <BR>"; $element = strtolower($element); if(eregi($this->head_tag,$element)) { $this->count++; $this->cur_entry_fields = array(); } else if(!array_key_exists($element,$this->group_fields)) { if(array_key_exists($element,$this->cur_entry_fields)) { $this->cur_entry_fields[$element]++; } else { $this->cur_entry_fields[$element] = 1; } } } function endHandler($xp, $element) { if(eregi($this->head_tag,$element)) { foreach($this->cur_entry_fields as $field=>$count) { if(array_key_exists($field,$this->main_fields)) { if($count > $this->main_fields[$field]) { $this->main_fields[$field] = $count; } } else { $this->main_fields[$field] = $count; } } } } function cDataHandler($xp, $data) { } function get_root_fields() { set_time_limit(1000); $in = fopen($this->xml_file,"r"); while($line = fgets($in)) { $xml = ereg_replace("&","amp;",$line); $good_parse = xml_parse($this->parser,$xml,false); if(!$good_parse) { echo "BAD PARSE: ".xml_get_current_line_number($this->parser)."<BR>"; } } ksort($this->main_fields); return $this->main_fields; } } ?>