ArrayToXml
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
void
void
bool
isArrayAllKeySequential(array|string $value)
Check if all array keys are sequential.
void
createRootElement(array|string $rootElement)
Create the root element.
void
Details
__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.
DOMDocument
toDom()
Return as DOM object.
protected void
addNode(DOMElement $domElement, string $key, array $value)
Add node.
protected void
addCollectionNode(DOMElement $domElement, array $value)
Add collection node.
protected void
addSequentialNode(DOMElement $domElement, array $value)
Add sequential node.
protected bool
isArrayAllKeySequential(array|string $value)
Check if all array keys are sequential.
protected void
addAttributes(DOMElement $domElement, string[] $data)
Add attributes.
protected DOMElement
createRootElement(array|string $rootElement)
Create the root element.
protected void
convertElement(DOMElement $domElement, array|string $value)
Parse individual element.