ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilSaxParser Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for ilSaxParser:
+ Collaboration diagram for ilSaxParser:

Public Member Functions

 __construct (?string $path_to_file='', ?bool $throw_exception=false)
 
 setXMLContent (string $a_xml_content)
 
 getXMLContent ()
 
 getInputType ()
 
 startParsing ()
 stores xml data in array More...
 
 createParser ()
 
 setHandlers ($a_xml_parser)
 
 parse ($a_xml_parser, $a_fp=null)
 

Data Fields

string $xml_file
 
bool $throw_exception = false
 

Protected Member Functions

 openXMLFile ()
 
 handleError (string $message)
 
 setThrowException (bool $throw_exception)
 

Protected Attributes

ilLanguage $lng = null
 

Private Member Functions

 setOptions ($a_xml_parser)
 
 freeParser ($a_xml_parser)
 

Private Attributes

const TYPE_FILE = 'file'
 
const TYPE_STRING = 'string'
 
string $input_type
 XML-Content type 'file' or 'string' If you choose file set the filename in constructor If you choose 'String' call the constructor with no argument and use setXMLContent() More...
 
string $xml_content
 XML-Content in case of content type 'string'. More...
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and implement their own handler methods

Deprecated:
We should move to native XML-Parsing

Definition at line 25 of file class.ilSaxParser.php.

Constructor & Destructor Documentation

◆ __construct()

ilSaxParser::__construct ( ?string  $path_to_file = '',
?bool  $throw_exception = false 
)

Definition at line 49 of file class.ilSaxParser.php.

References $DIC, and ILIAS\Repository\lng().

52  {
53  global $DIC;
54 
55  if ($path_to_file !== null && $path_to_file !== '') {
56  $this->xml_file = $path_to_file;
57  $this->input_type = self::TYPE_FILE;
58  } else {
59  $this->input_type = self::TYPE_STRING;
60  $this->xml_content = '';
61  }
62 
63  $this->throw_exception = $throw_exception ?? false;
64  $this->lng = $DIC->isDependencyAvailable('language')
65  ? $DIC->language()
66  : null;
67  }
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ createParser()

ilSaxParser::createParser ( )
Returns
resource
Exceptions
ilSaxParserExceptionor ILIAS Error

Definition at line 118 of file class.ilSaxParser.php.

References handleError().

Referenced by startParsing().

119  {
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");
123  }
124  return $xml_parser;
125  }
handleError(string $message)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ freeParser()

ilSaxParser::freeParser (   $a_xml_parser)
private
Parameters
resource$a_xml_parser
Exceptions
ilSaxParserException

Definition at line 198 of file class.ilSaxParser.php.

References handleError().

Referenced by startParsing().

198  : void
199  {
200  if (!xml_parser_free($a_xml_parser)) {
201  $this->handleError("Error freeing xml parser handle");
202  }
203  }
handleError(string $message)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInputType()

ilSaxParser::getInputType ( )

Definition at line 80 of file class.ilSaxParser.php.

References $input_type.

Referenced by SurveyImportParser\parse(), parse(), ilPluginReader\startParsing(), and startParsing().

80  : string
81  {
82  return $this->input_type;
83  }
string $input_type
XML-Content type 'file' or 'string' If you choose file set the filename in constructor If you choose ...
+ Here is the caller graph for this function:

◆ getXMLContent()

ilSaxParser::getXMLContent ( )

Definition at line 75 of file class.ilSaxParser.php.

References $xml_content.

Referenced by SurveyImportParser\parse(), and parse().

75  : string
76  {
77  return $this->xml_content;
78  }
string $xml_content
XML-Content in case of content type 'string'.
+ Here is the caller graph for this function:

◆ handleError()

ilSaxParser::handleError ( string  $message)
protected
Exceptions
ilSaxParserException

Definition at line 187 of file class.ilSaxParser.php.

Referenced by createParser(), freeParser(), openXMLFile(), parse(), and startParsing().

187  : void
188  {
189  if ($this->throw_exception) {
190  throw new ilSaxParserException($message);
191  }
192  }
SaxParserException thrown by ilSaxParser if property throwException is set.
$message
Definition: xapiexit.php:32
+ Here is the caller graph for this function:

◆ openXMLFile()

ilSaxParser::openXMLFile ( )
protected
Returns
resource
Exceptions
ilSaxParserException

Definition at line 143 of file class.ilSaxParser.php.

References handleError().

Referenced by startParsing().

144  {
145  if (!($fp = fopen($this->xml_file, 'r'))) {
146  $this->handleError("Cannot open xml file \"" . $this->xml_file . "\"");
147  }
148  return $fp;
149  }
handleError(string $message)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse()

ilSaxParser::parse (   $a_xml_parser,
  $a_fp = null 
)
Parameters
resource$a_xml_parser
resource | null$a_fp
Exceptions
ilSaxParserException

Definition at line 156 of file class.ilSaxParser.php.

References $data, getInputType(), getXMLContent(), and handleError().

Referenced by startParsing().

156  : void
157  {
158  $parse_status = true;
159  switch ($this->getInputType()) {
160  case self::TYPE_FILE:
161  while ($data = fread($a_fp, 4096)) {
162  $parse_status = xml_parse($a_xml_parser, $data, feof($a_fp));
163  }
164  break;
165 
166  case self::TYPE_STRING:
167  $parse_status = xml_parse($a_xml_parser, $this->getXMLContent());
168  break;
169  }
170  $error_code = xml_get_error_code($a_xml_parser);
171  if (!$parse_status && ($error_code !== XML_ERROR_NONE)) {
172  $error = sprintf(
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),
177  $error_code
178  );
179 
180  $this->handleError($error);
181  }
182  }
handleError(string $message)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setHandlers()

ilSaxParser::setHandlers (   $a_xml_parser)
abstract
Parameters
XMLParser | resource$a_xml_parser
Returns
void

Referenced by setOptions(), and startParsing().

+ Here is the caller graph for this function:

◆ setOptions()

ilSaxParser::setOptions (   $a_xml_parser)
private

Definition at line 128 of file class.ilSaxParser.php.

References setHandlers().

Referenced by startParsing().

128  : void
129  {
130  xml_parser_set_option($a_xml_parser, XML_OPTION_CASE_FOLDING, false);
131  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setThrowException()

ilSaxParser::setThrowException ( bool  $throw_exception)
protected

Definition at line 206 of file class.ilSaxParser.php.

References $throw_exception.

Referenced by ilSoapMailXmlParser\__construct(), ilFolderXmlParser\__construct(), and ilWebLinkXmlParser\__construct().

206  : void
207  {
208  $this->throw_exception = $throw_exception;
209  }
+ Here is the caller graph for this function:

◆ setXMLContent()

◆ startParsing()

ilSaxParser::startParsing ( )

stores xml data in array

Exceptions
ilSaxParserException

Definition at line 89 of file class.ilSaxParser.php.

References createParser(), freeParser(), getInputType(), handleError(), openXMLFile(), parse(), setHandlers(), and setOptions().

Referenced by ilManifestParser\__construct(), ilDataSetImportParser\__construct(), ilSoapMailXmlParser\start(), ilFolderXmlParser\start(), ilLearningSequenceXMLParser\start(), ilExerciseXMLParser\start(), and ilFileXMLParser\start().

89  : void
90  {
91  $xml_parser = $this->createParser();
92  $this->setOptions($xml_parser);
93  $this->setHandlers($xml_parser);
94 
95  switch ($this->getInputType()) {
96  case self::TYPE_FILE:
97  $fp = $this->openXMLFile();
98  $this->parse($xml_parser, $fp);
99  break;
100 
101  case self::TYPE_STRING:
102  $this->parse($xml_parser);
103  break;
104 
105  default:
106  $this->handleError(
107  "No input type given. Set filename in constructor or choose setXMLContent()"
108  );
109  break;
110  }
111  $this->freeParser($xml_parser);
112  }
setOptions($a_xml_parser)
freeParser($a_xml_parser)
parse($a_xml_parser, $a_fp=null)
handleError(string $message)
setHandlers($a_xml_parser)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $input_type

string ilSaxParser::$input_type
private

XML-Content type 'file' or 'string' If you choose file set the filename in constructor If you choose 'String' call the constructor with no argument and use setXMLContent()

Definition at line 35 of file class.ilSaxParser.php.

Referenced by getInputType().

◆ $lng

◆ $throw_exception

bool ilSaxParser::$throw_exception = false

Definition at line 46 of file class.ilSaxParser.php.

Referenced by ilObjectXMLParser\__construct(), and setThrowException().

◆ $xml_content

string ilSaxParser::$xml_content
private

XML-Content in case of content type 'string'.

Definition at line 40 of file class.ilSaxParser.php.

Referenced by getXMLContent().

◆ $xml_file

string ilSaxParser::$xml_file

Definition at line 44 of file class.ilSaxParser.php.

◆ TYPE_FILE

const ilSaxParser::TYPE_FILE = 'file'
private

Definition at line 27 of file class.ilSaxParser.php.

◆ TYPE_STRING

const ilSaxParser::TYPE_STRING = 'string'
private

Definition at line 28 of file class.ilSaxParser.php.


The documentation for this class was generated from the following file: