Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00036 class ilSaxParser extends PEAR
00037 {
00043 var $ilias;
00044
00050 var $lng;
00051
00057 var $xml_file;
00058
00064 function ilSaxParser($a_xml_file)
00065 {
00066 global $ilias, $lng;
00067
00068 $this->xml_file = $a_xml_file;
00069
00070 $this->ilias = &$ilias;
00071 $this->lng = &$lng;
00072 }
00073
00079 function startParsing()
00080 {
00081 $xml_parser = $this->createParser();
00082 $this->setOptions($xml_parser);
00083 $this->setHandlers($xml_parser);
00084 $fp = $this->openXMLFile();
00085 $this->parse($xml_parser,$fp);
00086 $this->freeParser($xml_parser);
00087 }
00093 function createParser()
00094 {
00095 $xml_parser = xml_parser_create("UTF-8");
00096
00097 if($xml_parser == false)
00098 {
00099 $this->ilias->raiseError("Cannot create an XML parser handle",$this->ilias->error_obj->FATAL);
00100 }
00101 return $xml_parser;
00102 }
00108 function setOptions($a_xml_parser)
00109 {
00110 xml_parser_set_option($a_xml_parser,XML_OPTION_CASE_FOLDING,false);
00111 }
00117 function setHandlers($a_xml_parser)
00118 {
00119 }
00125 function openXMLFile()
00126 {
00127 if(!($fp = fopen($this->xml_file,'r')))
00128 {
00129 $this->ilias->raiseError("Cannot open xml file",$this->ilias->error_obj->FATAL);
00130 }
00131 return $fp;
00132 }
00138 function parse($a_xml_parser,$a_fp)
00139 {
00140 while($data = fread($a_fp,4096))
00141 {
00142 $parseOk = xml_parse($a_xml_parser,$data,feof($a_fp));
00143 if(!$parseOk
00144 && (xml_get_error_code($a_xml_parser) != XML_ERROR_NONE))
00145 {
00146 $this->ilias->raiseError("XML Parse Error: ",$this->ilias->error_obj->FATAL);
00147 }
00148 }
00149 }
00155 function freeParser($a_xml_parser)
00156 {
00157 if(!xml_parser_free($a_xml_parser))
00158 {
00159 $this->ilias->raiseError("Error freeing xml parser handle ",$this->ilias->error_obj->FATAL);
00160 }
00161 }
00162 }
00163 ?>