Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
/lib/ -> xmlize.php (source)

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]

Code for parsing xml files. Handles functionality for:

Copyright: Kilian Singer
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 243 lines (9 kb)
Included or required: 1 time
Referenced: 1 time
Includes or requires: 0 files

Defines 2 classes

xml_format_exception:: (1 method):
  __construct()

core_xml_parser:: (5 methods):
  startelement()
  endelement()
  characterdata()
  parse()
  xmlize()


Class: xml_format_exception  - X-Ref

__construct($errorstring, $line, $char, $link = '')   X-Ref
Constructor function

param: string $errorstring Errorstring
param: int $line Linenumber
param: char $char Errorcharacter
param: string $link Link

Class: core_xml_parser  - X-Ref

Class for parsing xml files.

Handles functionality for:

Import of xml files in questionbank and course import.
Can handle xml files larger than 10MB through chunking the input file.
Uses a similar interface to the original version xmlize() by Hans Anderson.

startelement($parser, $name, $attrs)   X-Ref
Is called when tags are opened.

Note: Used by xml element handler as callback.

param: resource $parser The XML parser resource.
param: string $name The XML source to parse.
param: array $attrs Stores attributes of XML tag.
author: Kilian Singer

endelement($parser, $name)   X-Ref
Is called when tags are closed.

Note: Used by xml element handler as callback.

param: resource $parser The XML parser resource.
param: string $name The XML source to parse.
author: Kilian Singer

characterdata($parser, $data)   X-Ref
Is called for text between the start and the end of tags.

Note: Used by xml element handler as callback.

param: resource $parser The XML parser resource.
param: string $data The XML source to parse.
author: Kilian Singer

parse($data, $whitespace = 1, $encoding = 'UTF-8', $reporterrors = false)   X-Ref
Parses XML string.

Note: Interface is kept equal to previous version.

param: string $data the XML source to parse.
param: int $whitespace If set to 1 allows the parser to skip "space" characters in xml document. Default is 1
param: string $encoding Specify an OUTPUT encoding. If not specified, it defaults to UTF-8.
param: bool $reporterrors if set to true, then a {@link xml_format_exception}
author: Kilian Singer
return: array representation of the parsed XML.

xmlize($data, $whitespace = 1, $encoding = 'UTF-8', $reporterrors = false)   X-Ref
XML parsing function calles into class.

Note: Used by xml element handler as callback.

param: string $data the XML source to parse.
param: int $whitespace If set to 1 allows the parser to skip "space" characters in xml document. Default is 1
param: string $encoding Specify an OUTPUT encoding. If not specified, it defaults to UTF-8.
param: bool $reporterrors if set to true, then a {@link xml_format_exception}
return: array representation of the parsed XML.