ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilXmlChecker.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24require_once("./Services/Xml/classes/class.ilSaxParser.php");
25
36{
42 var $size;
45 var $texts;
47
55 function ilXMLChecker($a_xml_file = '')
56 {
57 parent::ilSaxParser($a_xml_file);
58 $this->has_error = FALSE;
59 }
60
66 function setHandlers($a_xml_parser)
67 {
68 xml_set_object($a_xml_parser,$this);
69 xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
70 xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
71 }
72
76 function startParsing()
77 {
78 parent::startParsing();
79 }
80
86 function parse($a_xml_parser,$a_fp = null)
87 {
88 switch($this->getInputType())
89 {
90 case 'file':
91
92 while($data = fread($a_fp,4096))
93 {
94 $parseOk = xml_parse($a_xml_parser,$data,feof($a_fp));
95 }
96 break;
97
98 case 'string':
99 $parseOk = xml_parse($a_xml_parser,$this->getXMLContent());
100 break;
101 }
102 if(!$parseOk
103 && (xml_get_error_code($a_xml_parser) != XML_ERROR_NONE))
104 {
105 $this->error_code = xml_get_error_code($a_xml_parser);
106 $this->error_line = xml_get_current_line_number($a_xml_parser);
107 $this->error_col = xml_get_current_column_number($a_xml_parser);
108 $this->error_msg = xml_error_string($a_xml_parser);
109 $this->has_error = TRUE;
110 return false;
111 }
112 return true;
113 }
114
118 function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
119 {
120 $this->elements++;
121 $this->attributes+=count($a_attribs);
122 }
123
127 function handlerEndTag($a_xml_parser, $a_name)
128 {
129 }
130
134 function handlerCharacterData($a_xml_parser, $a_data)
135 {
136 $this->texts++;
137 $this->text_size+=strlen($a_data);
138 }
139
140 function getErrorCode()
141 {
142 return $this->error_code;
143 }
144
145 function getErrorLine()
146 {
147 return $this->error_line;
148 }
149
150 function getErrorColumn()
151 {
152 return $this->error_col;
153 }
154
155 function getErrorMessage()
156 {
157 return $this->error_msg;
158 }
159
160 function getFullError()
161 {
162 return "Error: ".$this->error_msg." at line:".$this->error_line ." column:".$this->error_col;
163 }
164
165 function getXMLSize()
166 {
167 return $this->size;
168 }
169
170 function getXMLElements()
171 {
172 return $this->elements;
173 }
174
176 {
177 return $this->attributes;
178 }
179
181 {
182 return $this->texts;
183 }
184
185 function getXMLTextSize()
186 {
187 return $this->text_size;
188 }
189
190 function hasError()
191 {
192 return $this->has_error;
193 }
194
195}
196?>
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
ilXMLChecker($a_xml_file='')
Constructor.
setHandlers($a_xml_parser)
set event handler should be overwritten by inherited class @access private
handlerEndTag($a_xml_parser, $a_name)
handler for end of element
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
parse($a_xml_parser, $a_fp=null)
parse xml file
startParsing()
start the parser
$data