ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
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)
 

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 117 of file class.ilSaxParser.php.

118 {
119 $xml_parser = xml_parser_create("UTF-8");
120 if (!is_resource($xml_parser) && !is_object($xml_parser)) {
121 $this->handleError("Cannot create an XML parser handle");
122 }
123 return $xml_parser;
124 }
handleError(string $message)

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 186 of file class.ilSaxParser.php.

186 : void
187 {
188 if ($this->throw_exception) {
189 throw new ilSaxParserException($message);
190 }
191 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

Referenced by createParser(), 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 142 of file class.ilSaxParser.php.

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

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 155 of file class.ilSaxParser.php.

155 : void
156 {
157 $parse_status = true;
158 switch ($this->getInputType()) {
159 case self::TYPE_FILE:
160 while ($data = fread($a_fp, 4096)) {
161 $parse_status = xml_parse($a_xml_parser, $data, feof($a_fp));
162 }
163 break;
164
166 $parse_status = xml_parse($a_xml_parser, $this->getXMLContent());
167 break;
168 }
169 $error_code = xml_get_error_code($a_xml_parser);
170 if (!$parse_status && ($error_code !== XML_ERROR_NONE)) {
171 $error = sprintf(
172 "XML Parse Error: %s at line %s, col %s (Code: %s)",
173 xml_error_string($error_code),
174 xml_get_current_line_number($a_xml_parser),
175 xml_get_current_column_number($a_xml_parser),
176 $error_code
177 );
178
179 $this->handleError($error);
180 }
181 }

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 127 of file class.ilSaxParser.php.

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

Referenced by startParsing().

+ Here is the caller graph for this function:

◆ setThrowException()

ilSaxParser::setThrowException ( bool  $throw_exception)
protected

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

193 : void
194 {
195 $this->throw_exception = $throw_exception;
196 }

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

References createParser(), 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

◆ 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: