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/char_classes_parser.php4
<? /** * char_classes_parser provides functionality for extracting character classes from a given xml file. * * char_classes_parser makes use of the event based parsing api provide by php. * * @deprecated This class does not exist in the php5 version. Instead, the simpleXML object provided by php5 is * used to load the xml document into a data structure and then extract the required information. */ class char_classes_parser { /** * In order for the XML parser to be used within a class, you must create a parser variable within that class. When * the parser is created, it gets assigned to this variable. Please see the docmentation at http://www.php.net for * further explanation. * @access public * @var parser */ var $parser; /** * The name of the currect character class being extracted. * * As the document is being parsed, the name of the currently character class is saved in this variable. Later * the name is used to store the character class in an associative array. * @access public * @var string */ var $name; /** * The array to be returned containing all the character classes. * * This array is associative and in the form $char_classes["name"] = "Character Class". * * @access public * @var array */ var $char_classes; /** * The current cDATA. * @access public * @var string */ var $data; /** * The constructor for creating this object with new parser object. * * Please see the PHP documentation at http://www.php.net for an explanation of why these particular methods * are used to set up the parser. */ function char_classes_parser() { $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->name = ""; $this->char_classes = array(); $this->data = ""; } /** * This function loads character classes from an array into the char_classes array associated with this object. * * This function is not directly related to the parsing. Rather, in addition to loading character classes from * an XML file, the webuser can supply character classes through an html form. The character classes are put into * an associative array and via this function, added to this object's character class set. * * @todo It's not entirely clear why this function should exist here. Rather, the character classes here should * probably be kept as a seperate entity. An object existing outside of this one should contain the array * containg the set of both xml character classes and user defined character classes. * * @param array $user_char_classes An associative array containing user defined character classes. * @return array The superset of xml character classes and user defined character classes. */ function load_user_char_classes($user_char_classes) { $char_classes = array(); foreach($user_char_classes as $char_class) { $char_class = trim($char_class); if($char_class != "") { $vals = explode(" = ",$char_class); $name = $vals[0]; $symbols = $vals[1]; $char_classes[$name] = $symbols; } } return $char_classes; } /** * The function for parsing a given xml document. * * @return array The character classes extracted from the xml document. */ function get_xml_char_classes($xml) { if(file_exists($xml)) { $in = fopen($xml,"r"); while($line = fgets($in)) { $xml = ereg_replace("&", "&",$line); $xml = ereg_replace("<", "<",$xml); $xml = ereg_replace(">", ">",$xml); xml_parse($this->parser,$line,false); } } return $this->char_classes; } function startHandler($xp, $element, $attribs) { //$element = strtolower($element); } /** * The endHandler does most of the work in this parse. When it identifies a "name" tag, it stores it in the $name * variable. When it encounters a "value" tag, it enters the name=CDATA pair into the char_classes array and * then sets the name variable to an empty string. */ function endHandler($xp, $element) { $element = strtolower($element); if($element == "name") { $this->name = $this->data; } else if($element == "value") { $this->char_classes[$this->name] = $this->data; $this->name = ""; } $this->data = ""; } /** * Take all cDATA and appended to the end of the $data variable value. */ function cDataHandler($xp, $data) { if(trim($data) != "") $this->data .= $data; } } ?>