ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 
)

Reimplemented in ilObjTestXMLParser.

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

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: shib_login.php:26

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

+ 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.

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)

References handleError().

Referenced by startParsing().

+ 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.

198 : void
199 {
200 if (!xml_parser_free($a_xml_parser)) {
201 $this->handleError("Error freeing xml parser handle");
202 }
203 }

References handleError().

Referenced by startParsing().

+ 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.

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

References $input_type.

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

+ Here is the caller graph for this function:

◆ getXMLContent()

ilSaxParser::getXMLContent ( )

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

75 : string
76 {
77 return $this->xml_content;
78 }
string $xml_content
XML-Content in case of content type 'string'.

References $xml_content.

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

+ 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.

187 : void
188 {
189 if ($this->throw_exception) {
191 }
192 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$message
Definition: xapiexit.php:31

References $message.

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

+ Here is the caller graph for this function:

◆ openXMLFile()

ilSaxParser::openXMLFile ( )
protected
Returns
resource
Exceptions
ilSaxParserException

Reimplemented in ilQTIParser.

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

144 {
145 if (!($fp = fopen($this->xml_file, 'r'))) {
146 $this->handleError("Cannot open xml file \"" . $this->xml_file . "\"");
147 }
148 return $fp;
149 }

References handleError().

Referenced by startParsing().

+ 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

Reimplemented in SurveyImportParser.

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

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

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

Referenced by startParsing().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setHandlers()

◆ setOptions()

ilSaxParser::setOptions (   $a_xml_parser)
private

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

128 : void
129 {
130 xml_parser_set_option($a_xml_parser, XML_OPTION_CASE_FOLDING, false);
131 }

Referenced by startParsing().

+ Here is the caller graph for this function:

◆ setThrowException()

ilSaxParser::setThrowException ( bool  $throw_exception)
protected

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

206 : void
207 {
208 $this->throw_exception = $throw_exception;
209 }

References $throw_exception.

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

+ Here is the caller graph for this function:

◆ setXMLContent()

◆ startParsing()

ilSaxParser::startParsing ( )

stores xml data in array

Exceptions
ilSaxParserException

Reimplemented in ilAdvancedMDRecordParser, ilCategoryXmlParser, ilExportFileParser, ilGroupXMLParser, ilSCORMPackageParser, ilStyleImportParser, ilQuestionPageParser, ilQTIParser, and ilWebLinkXmlParser.

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

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
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 }
freeParser($a_xml_parser)
parse($a_xml_parser, $a_fp=null)
setHandlers($a_xml_parser)
setOptions($a_xml_parser)

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

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

+ 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

ilLanguage ilSaxParser::$lng = null
protected

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

Referenced by ilQuestionPageParser\__construct().

◆ $throw_exception

bool ilSaxParser::$throw_exception = false

◆ $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.

Referenced by ilQuestionPageParser\__construct().

◆ TYPE_FILE

const ilSaxParser::TYPE_FILE = 'file'
private

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

Referenced by __construct(), parse(), and startParsing().

◆ TYPE_STRING

const ilSaxParser::TYPE_STRING = 'string'
private

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

Referenced by __construct(), parse(), setXMLContent(), and startParsing().


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