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.

Differences Between: [Versions 401 and 402] [Versions 401 and 403]

(no description)

File Size: 720 lines (33 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

XMLParser:: (11 methods):
  __construct()
  parse()
  xmlrpc_se()
  xmlrpc_se_any()
  xmlrpc_ee()
  xmlrpc_ee_fast()
  xmlrpc_ee_epi()
  xmlrpc_cd()
  xmlrpc_dh()
  guessEncoding()
  hasEncoding()


Class: XMLParser  - X-Ref

Deals with parsing the XML.

__construct(array $options = array()   X-Ref

param: array $options passed to the xml parser

parse($data, $returnType = self::RETURN_XMLRPCVALS, $accept = 3, $options = array()   X-Ref

param: string $data
param: string $returnType
param: int $accept a bit-combination of self::ACCEPT_REQUEST, self::ACCEPT_RESPONSE, self::ACCEPT_VALUE
param: array $options

xmlrpc_se($parser, $name, $attrs, $acceptSingleVals = false)   X-Ref
xml parser handler function for opening element tags.

param: resource $parser
param: string $name
param: $attrs
param: bool $acceptSingleVals DEPRECATED use the $accept parameter instead

xmlrpc_se_any($parser, $name, $attrs)   X-Ref
xml parser handler function for opening element tags.
Used in decoding xml chunks that might represent single xmlrpc values as well as requests, responses.

param: resource $parser
param: $name
param: $attrs

xmlrpc_ee($parser, $name, $rebuildXmlrpcvals = 1)   X-Ref
xml parser handler function for close element tags.

param: resource $parser
param: string $name
param: int $rebuildXmlrpcvals >1 for rebuilding xmlrpcvals, 0 for rebuilding php values, -1 for xmlrpc-extension compatibility

xmlrpc_ee_fast($parser, $name)   X-Ref
Used in decoding xmlrpc requests/responses without rebuilding xmlrpc Values.

param: resource $parser
param: string $name

xmlrpc_ee_epi($parser, $name)   X-Ref
Used in decoding xmlrpc requests/responses while building xmlrpc-extension Values (plain php for all but base64 and datetime).

param: resource $parser
param: string $name

xmlrpc_cd($parser, $data)   X-Ref
xml parser handler function for character data.

param: resource $parser
param: string $data

xmlrpc_dh($parser, $data)   X-Ref
xml parser handler function for 'other stuff', ie. not char data or
element start/end tag. In fact it only gets called on unknown entities...

param: $parser
param: string data

guessEncoding($httpHeader = '', $xmlChunk = '', $encodingPrefs = null)   X-Ref
xml charset encoding guessing helper function.
Tries to determine the charset encoding of an XML chunk received over HTTP.
NB: according to the spec (RFC 3023), if text/xml content-type is received over HTTP without a content-type,
we SHOULD assume it is strictly US-ASCII. But we try to be more tolerant of non conforming (legacy?) clients/servers,
which will be most probably using UTF-8 anyway...
In order of importance checks:
1. http headers
2. BOM
3. XML declaration
4. guesses using mb_detect_encoding()

param: string $httpHeader the http Content-type header
param: string $xmlChunk xml content buffer
param: string $encodingPrefs comma separated list of character encodings to be used as default (when mb extension is enabled).
return: string the encoding determined. Null if it can't be determined and mbstring is enabled,

hasEncoding($xmlChunk)   X-Ref
Helper function: checks if an xml chunk as a charset declaration (BOM or in the xml declaration)

param: string $xmlChunk
return: bool