ArrayToXml
class ArrayToXml (View source)
Convert PHP Array to XML
Class ArrayToXml
Properties
protected DOMDocument | $document | The root DOM Document. |
|
protected bool | $replaceSpacesByUnderScoresInKeyNames | Set to enable replacing space with underscore. |
Methods
__construct(array $array, string|array $rootElement = '', bool $replaceSpacesByUnderScoresInKeyNames = true, string $xmlEncoding = 'UTF-8', string $xmlVersion = '1.0')
Construct a new instance.
static string
convert(array $array, 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.
bool
isArrayAllKeySequential(array|string $value)
Check if array are all sequential.
createRootElement(string|array $rootElement)
Create the root element.
Details
__construct(array $array, string|array $rootElement = '', bool $replaceSpacesByUnderScoresInKeyNames = true, string $xmlEncoding = 'UTF-8', string $xmlVersion = '1.0')
Construct a new instance.
static string
convert(array $array, 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
addNode(DOMElement $element, string $key, string|string[] $value)
Add node.
protected
addCollectionNode(DOMElement $element, string|string[] $value)
internal | param string $key |
Add collection node.
protected
addSequentialNode(DOMElement $element, string|string[] $value)
internal | param string $key |
Add sequential node.
protected bool
isArrayAllKeySequential(array|string $value)
Check if array are all sequential.
protected
addAttributes(DOMElement $element, string[] $data)
Add attributes.
protected DOMElement
createRootElement(string|array $rootElement)
Create the root element.