class ArrayToXml (View source)

Properties

protected DOMDocument $domDocument

The DOM Document.

protected bool $replaceSpacesByUnderScoresInKeyNames

Set to enable replacing space with underscore.

Methods

__construct(array $content, array|string $rootElement = '', bool $replaceSpacesByUnderScoresInKeyNames = true, string $xmlEncoding = 'UTF-8', string $xmlVersion = '1.0')

Construct a new instance.

static string
convert(array $arr, string $rootElementName = 'document', bool $replaceSpacesByUnderScoresInKeyNames = true, string $xmlEncoding = 'UTF-8', string $xmlVersion = '1.0')

Convert the given array to an xml string.

string
toXml()

Return as XML.

toDom()

Return as DOM object.

void
addNode(DOMElement $domElement, string $key, array $value)

Add node.

void
addCollectionNode(DOMElement $domElement, array $value)

Add collection node.

void
addSequentialNode(DOMElement $domElement, array $value)

Add sequential node.

bool
isArrayAllKeySequential(array|string $value)

Check if all array keys are sequential.

void
addAttributes(DOMElement $domElement, string[] $data)

Add attributes.

createRootElement(array|string $rootElement)

Create the root element.

void
convertElement(DOMElement $domElement, array|string $value)

Parse individual element.

Details

__construct(array $content, array|string $rootElement = '', bool $replaceSpacesByUnderScoresInKeyNames = true, string $xmlEncoding = 'UTF-8', string $xmlVersion = '1.0')

Construct a new instance.

Parameters

array $content
array|string $rootElement
bool $replaceSpacesByUnderScoresInKeyNames
string $xmlEncoding
string $xmlVersion

Exceptions

DOMException

static string convert(array $arr, string $rootElementName = 'document', bool $replaceSpacesByUnderScoresInKeyNames = true, string $xmlEncoding = 'UTF-8', string $xmlVersion = '1.0')

Convert the given array to an xml string.

Parameters

array $arr
string $rootElementName
bool $replaceSpacesByUnderScoresInKeyNames
string $xmlEncoding
string $xmlVersion

Return Value

string

string toXml()

Return as XML.

Return Value

string

DOMDocument toDom()

Return as DOM object.

Return Value

DOMDocument

protected void addNode(DOMElement $domElement, string $key, array $value)

Add node.

Parameters

DOMElement $domElement
string $key
array $value

Return Value

void

protected void addCollectionNode(DOMElement $domElement, array $value)

Add collection node.

Parameters

DOMElement $domElement
array $value

Return Value

void

protected void addSequentialNode(DOMElement $domElement, array $value)

Add sequential node.

Parameters

DOMElement $domElement
array $value

Return Value

void

protected bool isArrayAllKeySequential(array|string $value)

Check if all array keys are sequential.

Parameters

array|string $value

Return Value

bool

protected void addAttributes(DOMElement $domElement, string[] $data)

Add attributes.

Parameters

DOMElement $domElement
string[] $data

Return Value

void

protected DOMElement createRootElement(array|string $rootElement)

Create the root element.

Parameters

array|string $rootElement

Return Value

DOMElement

protected void convertElement(DOMElement $domElement, array|string $value)

Parse individual element.

Parameters

DOMElement $domElement
array|string $value

Return Value

void