MediaWiki master
MediaWiki\Xml\Xml Class Reference

Module of static functions for generating XML. More...

Static Public Member Functions

static closeElement ( $element)
 Shortcut to close an XML element.
 
static element ( $element, $attribs=null, $contents='', $allowShortTag=true)
 Format an XML element with given attributes and, optionally, text content.
 
static elementClean ( $element, $attribs=[], $contents='')
 Format an XML element as with self::element(), but run text through the content language's normalize() validator first to ensure that no invalid UTF-8 is passed.
 
static escapeTagsOnly ( $in)
 Replace " > and < with their respective HTML entities ( ", >, <)
 
static expandAttributes (?array $attribs)
 Given an array of ('attributename' => 'value'), it generates the code to set the XML attributes : attributename="value".
 
static isWellFormedXmlFragment ( $text)
 Check if a string is a well-formed XML fragment.
 
static openElement ( $element, $attribs=null)
 This opens an XML element.
 
static tags ( $element, $attribs, $contents)
 Same as Xml::element(), but does not escape contents.
 

Detailed Description

Module of static functions for generating XML.

Definition at line 18 of file Xml.php.

Member Function Documentation

◆ closeElement()

static MediaWiki\Xml\Xml::closeElement ( $element)
static

Shortcut to close an XML element.

Parameters
string$elementElement name
Returns
string

Definition at line 110 of file Xml.php.

Referenced by MediaWiki\Api\ApiFormatXml\recXmlPrint().

◆ element()

static MediaWiki\Xml\Xml::element ( $element,
$attribs = null,
$contents = '',
$allowShortTag = true )
static

Format an XML element with given attributes and, optionally, text content.

Element and attribute names are assumed to be ready for literal inclusion. Strings are assumed to not contain XML-illegal characters; special characters (<, >, &) are escaped but illegals are not touched.

Parameters
string$elementElement name
array | null$attribsName=>value pairs. Values will be escaped.
string | null$contentsNull to make an open tag only; '' for a contentless closed tag (default)
bool$allowShortTagWhether '' in $contents will result in a contentless closed tag
Returns
string

Definition at line 35 of file Xml.php.

References MediaWiki\Xml\Xml\expandAttributes().

Referenced by MediaWiki\Xml\Xml\elementClean(), and MediaWiki\Api\ApiFormatXml\recXmlPrint().

◆ elementClean()

static MediaWiki\Xml\Xml::elementClean ( $element,
$attribs = [],
$contents = '' )
static

Format an XML element as with self::element(), but run text through the content language's normalize() validator first to ensure that no invalid UTF-8 is passed.

Parameters
string$element
array | null$attribsName=>value pairs. Values will be escaped.
string | null$contentsNull to make an open tag only; '' for a contentless closed tag (default)
Returns
string

Definition at line 83 of file Xml.php.

References MediaWiki\Xml\Xml\element(), and MediaWiki\MediaWikiServices\getInstance().

◆ escapeTagsOnly()

static MediaWiki\Xml\Xml::escapeTagsOnly ( $in)
static

Replace " > and < with their respective HTML entities ( ", >, <)

Parameters
string$inText that might contain HTML tags.
Returns
string Escaped string

Definition at line 179 of file Xml.php.

◆ expandAttributes()

static MediaWiki\Xml\Xml::expandAttributes ( ?array $attribs)
static

Given an array of ('attributename' => 'value'), it generates the code to set the XML attributes : attributename="value".

The values are passed to Sanitizer::encodeAttribute. Returns null or empty string if no attributes given.

Parameters
array | null$attribsArray of attributes for an XML element
Returns
null|string

Definition at line 61 of file Xml.php.

Referenced by MediaWiki\Xml\Xml\element(), and MediaWiki\Xml\Xml\openElement().

◆ isWellFormedXmlFragment()

static MediaWiki\Xml\Xml::isWellFormedXmlFragment ( $text)
static

Check if a string is a well-formed XML fragment.

Wraps fragment in an \<html\> bit and doctype, so it can be a fragment and can use HTML named entities.

Parameters
string$text
Returns
bool

Definition at line 162 of file Xml.php.

◆ openElement()

static MediaWiki\Xml\Xml::openElement ( $element,
$attribs = null )
static

This opens an XML element.

Parameters
string$elementName of the element
array | null$attribsArray of attributes, see Xml::expandAttributes()
Returns
string

Definition at line 101 of file Xml.php.

References MediaWiki\Xml\Xml\expandAttributes().

Referenced by MediaWiki\Api\ApiFormatXml\recXmlPrint(), and MediaWiki\Xml\Xml\tags().

◆ tags()

static MediaWiki\Xml\Xml::tags ( $element,
$attribs,
$contents )
static

Same as Xml::element(), but does not escape contents.

Handy when the content you have is already valid xml.

Parameters
string$elementElement name
array | null$attribsArray of attributes
string$contentsContent of the element
Returns
string

Definition at line 127 of file Xml.php.

References MediaWiki\Xml\Xml\openElement().


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