50 ?
string $path_to_file =
'',
55 if ($path_to_file !==
null && $path_to_file !==
'') {
56 $this->xml_file = $path_to_file;
60 $this->xml_content =
'';
64 $this->
lng = $DIC->isDependencyAvailable(
'language')
71 $this->xml_content = $a_xml_content;
98 $this->
parse($xml_parser, $fp);
102 $this->
parse($xml_parser);
107 "No input type given. Set filename in constructor or choose setXMLContent()"
120 $xml_parser = xml_parser_create(
"UTF-8");
121 if (!is_resource($xml_parser) && !is_object($xml_parser)) {
122 $this->
handleError(
"Cannot create an XML parser handle");
130 xml_parser_set_option($a_xml_parser, XML_OPTION_CASE_FOLDING,
false);
145 if (!($fp = fopen($this->xml_file,
'r'))) {
146 $this->
handleError(
"Cannot open xml file \"" . $this->xml_file .
"\"");
156 public function parse($a_xml_parser, $a_fp =
null): void
158 $parse_status =
true;
161 while (
$data = fread($a_fp, 4096)) {
162 $parse_status = xml_parse($a_xml_parser,
$data, feof($a_fp));
167 $parse_status = xml_parse($a_xml_parser, $this->
getXMLContent());
170 $error_code = xml_get_error_code($a_xml_parser);
171 if (!$parse_status && ($error_code !== XML_ERROR_NONE)) {
173 "XML Parse Error: %s at line %s, col %s (Code: %s)",
174 xml_error_string($error_code),
175 xml_get_current_line_number($a_xml_parser),
176 xml_get_current_column_number($a_xml_parser),
189 if ($this->throw_exception) {
200 if (!xml_parser_free($a_xml_parser)) {
201 $this->
handleError(
"Error freeing xml parser handle");
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
freeParser($a_xml_parser)
parse($a_xml_parser, $a_fp=null)
string $xml_content
XML-Content in case of content type 'string'.
setXMLContent(string $a_xml_content)
handleError(string $message)
setThrowException(bool $throw_exception)
startParsing()
stores xml data in array
setHandlers($a_xml_parser)
__construct(?string $path_to_file='', ?bool $throw_exception=false)
string $input_type
XML-Content type 'file' or 'string' If you choose file set the filename in constructor If you choose ...
setOptions($a_xml_parser)