Typo3XmlParser
Decodes XML string to PHP array.
A dedicated set of node attributes is considered during conversion:
- attribute "index" specifies the final node name which is used as key in the PHP array
- attribute "type" specifies the node value type which is used for casting
- attribute "base64" specifies the node value type being binary and requiring a base64-decoding These attributes were applied during encoding of the PHP array with XmlEncoder::encode().
The node name "n{number}" is converted to a number-indexed array key "{number}".
still experimental
Table of Contents
Methods
- decode() : array<string|int, mixed>|string
- decodeWithReturningExceptionAsString() : array<string|int, mixed>|string
- This method serves as a wrapper for decode() and is used to replace GeneralUtility::xml2array(), which returns an exception as a string instead of throwing it.
- disableNamespaceInNodeNames() : string
- DOMDocument::loadXML() breaks if prefixes of undefined namespaces are used in node names: Replace namespace divider ":" by temporary "___" string before parsing the XML.
- parseXml() : array<string|int, mixed>|string|null
- reactivateNamespaceInNodeName() : string
- Re-insert the namespace divider ":" into single node name again after parsing the XML.
- reactivateNamespaceInNodeNames() : string
- Re-insert the namespace divider ":" into all node names again after parsing the XML.
Methods
decode()
public
decode(string $xml[, Typo3XmlSerializerOptions|null $options = null ]) : array<string|int, mixed>|string
Parameters
- $xml : string
-
XML string
- $options : Typo3XmlSerializerOptions|null = null
-
Apply specific decoding configuration - Ignored node types, libxml2 options, ...
Tags
Return values
array<string|int, mixed>|string —PHP array - or a string if the XML root node is empty
decodeWithReturningExceptionAsString()
This method serves as a wrapper for decode() and is used to replace GeneralUtility::xml2array(), which returns an exception as a string instead of throwing it.
public
decodeWithReturningExceptionAsString(string $xml[, Typo3XmlSerializerOptions|null $options = null ]) : array<string|int, mixed>|string
In perspective, all uses of this method should be replaced by decode() and the exceptions should be handled locally.
Parameters
- $xml : string
-
XML string
- $options : Typo3XmlSerializerOptions|null = null
-
Decoding configuration - see decode() for details
Return values
array<string|int, mixed>|string —PHP array - or a string if the XML root node is empty or an exception
disableNamespaceInNodeNames()
DOMDocument::loadXML() breaks if prefixes of undefined namespaces are used in node names: Replace namespace divider ":" by temporary "___" string before parsing the XML.
protected
disableNamespaceInNodeNames(string $value) : string
Parameters
- $value : string
Return values
stringparseXml()
protected
parseXml(DOMNode $node, Typo3XmlSerializerOptions $options) : array<string|int, mixed>|string|null
Parameters
- $node : DOMNode
- $options : Typo3XmlSerializerOptions
Return values
array<string|int, mixed>|string|nullreactivateNamespaceInNodeName()
Re-insert the namespace divider ":" into single node name again after parsing the XML.
protected
reactivateNamespaceInNodeName(string $value) : string
Parameters
- $value : string
Return values
stringreactivateNamespaceInNodeNames()
Re-insert the namespace divider ":" into all node names again after parsing the XML.
protected
reactivateNamespaceInNodeNames(string $value) : string
Parameters
- $value : string