Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

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

(no description)

Copyright: 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 287 lines (11 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 2 classes

xml_writer:: (14 methods):
  __construct()
  start()
  stop()
  set_nonamespace_schema()
  set_prologue()
  begin_tag()
  end_tag()
  full_tag()
  write()
  get_default_prologue()
  xml_safe_attr_content()
  xml_safe_text_content()
  xml_safe_utf8()
  text_content()

xml_writer_exception:: (1 method):
  __construct()


Class: xml_writer  - X-Ref

Class implementing one (more or less complete) UTF-8 XML writer

General purpose class used to output UTF-8 XML contents easily. Can be customized
using implementations of @xml_output (to define where to send the xml) and
and @xml_contenttransformer (to perform any transformation in contents before
outputting the XML).

Has support for attributes, basic w3c xml schemas declaration,
and performs some content cleaning to avoid potential incorret UTF-8
mess and has complete exception support.

TODO: Provide UTF-8 safe strtoupper() function if using casefolding and non-ascii tags/attrs names
TODO: Finish phpdocs
__construct($output, $contenttransformer = null, $casefolding = false)   X-Ref
No description

start()   X-Ref
Initializes the XML writer, preparing it to accept instructions, also
invoking the underlying @xml_output init method to be ready for operation


stop()   X-Ref
Finishes the XML writer, not accepting instructions any more, also
invoking the underlying @xml_output finish method to close/flush everything as needed


set_nonamespace_schema($uri)   X-Ref
Set the URI location for the *nonamespace* schema to be used by the (whole) XML document


set_prologue($prologue)   X-Ref
Define the complete prologue to be used, replacing the simple, default one


begin_tag($tag, $attributes = null)   X-Ref
Outputs one XML start tag with optional attributes (name => value array)


end_tag($tag)   X-Ref
Outputs one XML end tag


full_tag($tag, $content = null, $attributes = null)   X-Ref
Outputs one tag completely (open, contents and close)


write($output)   X-Ref
Send some XML formatted chunk to output.


get_default_prologue()   X-Ref
Get default prologue contents for this writer if there isn't a custom one


xml_safe_attr_content($content)   X-Ref
Clean attribute content and encode needed chars
(&, <, >, ") - single quotes not needed in this class
as far as we are enclosing with "


xml_safe_text_content($content)   X-Ref
Clean text content and encode needed chars
(&, <, >)


xml_safe_utf8($content)   X-Ref
Perform some UTF-8 cleaning, stripping the control chars (\x0-\x1f)
but tabs (\x9), newlines (\xa) and returns (\xd). The delete control
char (\x7f) is also included. All them are forbiden in XML 1.0 specs.
The expression below seems to be UTF-8 safe too because it simply
ignores the rest of characters. Also normalize linefeeds and return chars.


text_content($content)   X-Ref
Returns text contents processed by the corresponding @xml_contenttransformer


Class: xml_writer_exception  - X-Ref

__construct($errorcode, $a=NULL, $debuginfo=null)   X-Ref
No description