ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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{
39 public $error_col;
40 public $error_msg;
41 public $has_error;
42 public $size;
43 public $elements;
45 public $texts;
46 public $text_size;
47
55 public function __construct($a_xml_file = '', $throwException = false)
56 {
58 $this->has_error = false;
59 }
60
66 public 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 public function startParsing()
77 {
78 parent::startParsing();
79 }
80
86 public function parse($a_xml_parser, $a_fp = null)
87 {
88 switch ($this->getInputType()) {
89 case 'file':
90
91 while ($data = fread($a_fp, 4096)) {
92 $parseOk = xml_parse($a_xml_parser, $data, feof($a_fp));
93 }
94 break;
95
96 case 'string':
97 $parseOk = xml_parse($a_xml_parser, $this->getXMLContent());
98 break;
99 }
100 if (!$parseOk
101 && (xml_get_error_code($a_xml_parser) != XML_ERROR_NONE)) {
102 $this->error_code = xml_get_error_code($a_xml_parser);
103 $this->error_line = xml_get_current_line_number($a_xml_parser);
104 $this->error_col = xml_get_current_column_number($a_xml_parser);
105 $this->error_msg = xml_error_string($a_xml_parser);
106 $this->has_error = true;
107 return false;
108 }
109 return true;
110 }
111
115 public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
116 {
117 $this->elements++;
118 $this->attributes += count($a_attribs);
119 }
120
124 public function handlerEndTag($a_xml_parser, $a_name)
125 {
126 }
127
131 public function handlerCharacterData($a_xml_parser, $a_data)
132 {
133 $this->texts++;
134 $this->text_size += strlen($a_data);
135 }
136
137 public function getErrorCode()
138 {
139 return $this->error_code;
140 }
141
142 public function getErrorLine()
143 {
144 return $this->error_line;
145 }
146
147 public function getErrorColumn()
148 {
149 return $this->error_col;
150 }
151
152 public function getErrorMessage()
153 {
154 return $this->error_msg;
155 }
156
157 public function getFullError()
158 {
159 return "Error: " . $this->error_msg . " at line:" . $this->error_line . " column:" . $this->error_col;
160 }
161
162 public function getXMLSize()
163 {
164 return $this->size;
165 }
166
167 public function getXMLElements()
168 {
169 return $this->elements;
170 }
171
172 public function getXMLAttributes()
173 {
174 return $this->attributes;
175 }
176
177 public function getXMLTextSections()
178 {
179 return $this->texts;
180 }
181
182 public function getXMLTextSize()
183 {
184 return $this->text_size;
185 }
186
187 public function hasError()
188 {
189 return $this->has_error;
190 }
191}
An exception for terminatinating execution or to throw for unit testing.
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
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
__construct($a_xml_file='', $throwException=false)
Constructor.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$data
Definition: storeScorm.php:23