‪TYPO3CMS  ‪main
TYPO3\CMS\Core\Serializer\Typo3XmlParser Class Reference

Public Member Functions

array string decodeWithReturningExceptionAsString (string $xml, Typo3XmlSerializerOptions $options=null)
 
array string decode (string $xml, Typo3XmlSerializerOptions $options=null)
 

Protected Member Functions

 disableNamespaceInNodeNames (string $value)
 
 reactivateNamespaceInNodeNames (string $value)
 
 reactivateNamespaceInNodeName (string $value)
 
 parseXml (\DOMNode $node, Typo3XmlSerializerOptions $options)
 

Detailed Description

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

Definition at line 37 of file Typo3XmlParser.php.

Member Function Documentation

◆ decode()

array string TYPO3\CMS\Core\Serializer\Typo3XmlParser::decode ( string  $xml,
Typo3XmlSerializerOptions  $options = null 
)
Parameters
string$xml‪XML string
Typo3XmlSerializerOptions | null$options‪Apply specific decoding configuration - Ignored node types, libxml2 options, ...
Returns
‪array|string PHP array - or a string if the XML root node is empty
Exceptions
InvalidDataException

Definition at line 66 of file Typo3XmlParser.php.

References TYPO3\CMS\Core\Serializer\Typo3XmlParser\disableNamespaceInNodeNames(), TYPO3\CMS\Core\Serializer\Typo3XmlParser\parseXml(), and TYPO3\CMS\Core\Serializer\Typo3XmlParser\reactivateNamespaceInNodeName().

Referenced by TYPO3\CMS\Core\Serializer\Typo3XmlParser\decodeWithReturningExceptionAsString().

◆ decodeWithReturningExceptionAsString()

array string TYPO3\CMS\Core\Serializer\Typo3XmlParser::decodeWithReturningExceptionAsString ( string  $xml,
Typo3XmlSerializerOptions  $options = null 
)

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. In perspective, all uses of this method should be replaced by decode() and the exceptions should be handled locally.

Parameters
string$xml‪XML string
Typo3XmlSerializerOptions | null$options‪Decoding configuration - see decode() for details
Returns
‪array|string PHP array - or a string if the XML root node is empty or an exception

Definition at line 49 of file Typo3XmlParser.php.

References TYPO3\CMS\Core\Serializer\Typo3XmlParser\decode().

◆ disableNamespaceInNodeNames()

TYPO3\CMS\Core\Serializer\Typo3XmlParser::disableNamespaceInNodeNames ( string  $value)
protected

DOMDocument::loadXML() breaks if prefixes of undefined namespaces are used in node names: Replace namespace divider ":" by temporary "___" string before parsing the XML.

Definition at line 149 of file Typo3XmlParser.php.

Referenced by TYPO3\CMS\Core\Serializer\Typo3XmlParser\decode().

◆ parseXml()

◆ reactivateNamespaceInNodeName()

TYPO3\CMS\Core\Serializer\Typo3XmlParser::reactivateNamespaceInNodeName ( string  $value)
protected

Re-insert the namespace divider ":" into single node name again after parsing the XML.

Definition at line 177 of file Typo3XmlParser.php.

Referenced by TYPO3\CMS\Core\Serializer\Typo3XmlParser\decode(), and TYPO3\CMS\Core\Serializer\Typo3XmlParser\parseXml().

◆ reactivateNamespaceInNodeNames()

TYPO3\CMS\Core\Serializer\Typo3XmlParser::reactivateNamespaceInNodeNames ( string  $value)
protected

Re-insert the namespace divider ":" into all node names again after parsing the XML.

Definition at line 161 of file Typo3XmlParser.php.

Referenced by TYPO3\CMS\Core\Serializer\Typo3XmlParser\parseXml().