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

Modules/Test/classes/class.ilXMLChecker.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 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 require_once("./classes/class.ilSaxParser.php");
00025 
00035 class ilXMLChecker extends ilSaxParser
00036 {
00037   var $error_code;
00038   var $error_line;
00039   var $error_col;
00040   var $error_msg;
00041         var $has_error;
00042   var $size;
00043   var $elements;
00044   var $attributes;
00045   var $texts;
00046   var $text_size;
00047         
00055         function ilXMLChecker($a_xml_file = '')
00056         {
00057                 parent::ilSaxParser($a_xml_file);
00058                 $this->has_error = FALSE;
00059         }
00060 
00066         function setHandlers($a_xml_parser)
00067         {
00068                 xml_set_object($a_xml_parser,$this);
00069                 xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
00070                 xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
00071         }
00072 
00076         function startParsing()
00077         {
00078                 parent::startParsing();
00079         }
00080 
00086         function parse($a_xml_parser,$a_fp = null)
00087         {
00088                 switch($this->getInputType())
00089                 {
00090                         case 'file':
00091 
00092                                 while($data = fread($a_fp,4096))
00093                                 {
00094                                         $parseOk = xml_parse($a_xml_parser,$data,feof($a_fp));
00095                                 }
00096                                 break;
00097                                 
00098                         case 'string':
00099                                 $parseOk = xml_parse($a_xml_parser,$this->getXMLContent());
00100                                 break;
00101                 }
00102                 if(!$parseOk
00103                    && (xml_get_error_code($a_xml_parser) != XML_ERROR_NONE))
00104                 {
00105       $this->error_code = xml_get_error_code($a_xml_parser);
00106       $this->error_line = xml_get_current_line_number($a_xml_parser);
00107       $this->error_col = xml_get_current_column_number($a_xml_parser);
00108       $this->error_msg = xml_error_string($a_xml_parser);
00109                         $this->has_error = TRUE;
00110                         return false;
00111                 }
00112                 return true;
00113         }
00114         
00118         function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
00119         {
00120     $this->elements++;
00121     $this->attributes+=count($a_attribs);
00122         }
00123 
00127         function handlerEndTag($a_xml_parser, $a_name)
00128         {
00129         }
00130 
00134         function handlerCharacterData($a_xml_parser, $a_data)
00135         {
00136     $this->texts++;
00137     $this->text_size+=strlen($a_data);
00138         }
00139 
00140   function getErrorCode() 
00141         {
00142     return $this->error_code; 
00143   }
00144   
00145   function getErrorLine() 
00146         {
00147     return $this->error_line; 
00148   }
00149   
00150   function getErrorColumn() 
00151         {
00152     return $this->error_col; 
00153   }
00154   
00155   function getErrorMessage() 
00156         {
00157     return $this->error_msg; 
00158   }
00159   
00160   function getFullError() 
00161         {
00162     return "Error: ".$this->error_msg." at line:".$this->error_line ." column:".$this->error_col;
00163   }
00164   
00165   function getXMLSize() 
00166         {
00167     return $this->size; 
00168   }
00169   
00170   function getXMLElements() 
00171         {
00172     return $this->elements; 
00173   }
00174   
00175   function getXMLAttributes() 
00176         {
00177     return $this->attributes; 
00178   }
00179   
00180   function getXMLTextSections() 
00181         {
00182     return $this->texts; 
00183   }
00184   
00185   function getXMLTextSize() 
00186         {
00187     return $this->text_size; 
00188   }
00189   
00190   function hasError() 
00191         {
00192     return $this->has_error; 
00193   }
00194   
00195 }
00196 ?>

Generated on Fri Dec 13 2013 17:56:53 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1