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 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 ?>