Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
xml_writer Class Reference

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

Public Member Functions

 __construct ($output, $contenttransformer=null, $casefolding=false)
 
 begin_tag ($tag, $attributes=null)
 Outputs one XML start tag with optional attributes (name => value array)
 
 end_tag ($tag)
 Outputs one XML end tag.
 
 full_tag ($tag, $content=null, $attributes=null)
 Outputs one tag completely (open, contents and close)
 
 set_nonamespace_schema ($uri)
 Set the URI location for the nonamespace schema to be used by the (whole) XML document.
 
 set_prologue ($prologue)
 Define the complete prologue to be used, replacing the simple, default one.
 
 start ()
 Initializes the XML writer, preparing it to accept instructions, also invoking the underlying @xml_output init method to be ready for operation.
 
 stop ()
 Finishes the XML writer, not accepting instructions any more, also invoking the underlying @xml_output finish method to close/flush everything as needed.
 

Protected Member Functions

 get_default_prologue ()
 Get default prologue contents for this writer if there isn't a custom one.
 
 text_content ($content)
 Returns text contents processed by the corresponding @xml_contenttransformer.
 
 write ($output)
 Send some XML formatted chunk to output.
 
 xml_safe_attr_content ($content)
 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)
 Clean text content and encode needed chars (&, <, >)
 
 xml_safe_utf8 ($content)
 Perform some UTF-8 cleaning, stripping the control chars (x0-x1f) but tabs (x9), newlines (\xa) and returns (\xd).
 

Protected Attributes

 $casefolding
 
 $contenttransformer
 
 $lastwastext
 
 $level
 
 $nullcontent
 
 $opentags
 
 $output
 
 $prologue
 
 $running
 
 $xmlschema
 

Detailed Description

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

Member Function Documentation

◆ xml_safe_utf8()

xml_writer::xml_safe_utf8 ( $content)
protected

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.


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