class Xml (View source)

Constants

FLAG_PRESERVE_CARRIAGE_RETURNS

Methods

bool|null
getBool(SimpleXMLElement|null $elementOrAttribute, bool|null $default = false)

Extract a boolean from an element or an attribute value.

createChildElement(SimpleXMLElement $parentElement, string $childName, scalar|DateTimeInterface|Stringable $value, int $flags = 0)

Create a new element with the specified value.

void
appendCData(SimpleXMLElement $element, string $value)

Append a new CDATA section to an existing element.

createCDataNode(SimpleXMLElement $x, $nodeName, $content) deprecated

No description

string
serialize(scalar|DateTimeInterface|Stringable $value)

No description

bool
shouldUseCData(string $value)

Using a CDATA section is not mandatory: it'd be enough to call htmlentities(..., ENT_XML1).

Details

bool|null getBool(SimpleXMLElement|null $elementOrAttribute, bool|null $default = false)

Extract a boolean from an element or an attribute value.

Parameters

SimpleXMLElement|null $elementOrAttribute
bool|null $default

what should be returned if the element/attribute does not exist, or if it does not contain a boolean representation ('true', 'yes', 'on', '1', 'false', 'no', '0', '')

Return Value

bool|null

returns NULL if and only if $default is null and the attribute/element doesn't exist (or it has an invalid value)

SimpleXMLElement createChildElement(SimpleXMLElement $parentElement, string $childName, scalar|DateTimeInterface|Stringable $value, int $flags = 0)

Create a new element with the specified value.

Parameters

SimpleXMLElement $parentElement
string $childName
scalar|DateTimeInterface|Stringable $value
int $flags

Return Value

SimpleXMLElement

void appendCData(SimpleXMLElement $element, string $value)

Append a new CDATA section to an existing element.

Please remark that \r\n and \r sequences will be converted to \n - see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-line-ends

Parameters

SimpleXMLElement $element
string $value

Return Value

void

createCDataNode(SimpleXMLElement $x, $nodeName, $content) deprecated

deprecated use the createChildElement() method

No description

Parameters

SimpleXMLElement $x
$nodeName
$content

protected string serialize(scalar|DateTimeInterface|Stringable $value)

No description

Parameters

scalar|DateTimeInterface|Stringable $value

Return Value

string

protected bool shouldUseCData(string $value)

Using a CDATA section is not mandatory: it'd be enough to call htmlentities(..., ENT_XML1).

But CDATA is much more readable, so let's use it when values contains characters that must be escaped).

Parameters

string $value

Return Value

bool

See also

https://www.w3.org/TR/2008/REC-xml-20081126/#syntax