• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

classes/class.ilSaxParser.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
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 ?>

Generated on Fri Dec 13 2013 09:06:35 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1