From 30796a9f683751d74912b20d2aaef212be6ef6da Mon Sep 17 00:00:00 2001 From: Markus Hoelzle <typo3@markus-hoelzle.de> Date: Wed, 24 Dec 2014 02:17:38 +0100 Subject: [PATCH] [FEATURE] XML parser options for xml2tree() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow parser-options for xml_parser_set_option() to be supplied. Resolves: #59384 Releases: master Change-Id: I656b36f6252e7dce4ed94e4b9b916dec0fbe884f Reviewed-on: http://review.typo3.org/30973 Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de> Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de> Reviewed-by: Frank Nägler <frank.naegler@typo3.org> Tested-by: Frank Nägler <frank.naegler@typo3.org> --- .../core/Classes/Utility/GeneralUtility.php | 6 +++++- ...ature-59384-XMLParserOptionsForXml2tree.rst | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Feature-59384-XMLParserOptionsForXml2tree.rst diff --git a/typo3/sysext/core/Classes/Utility/GeneralUtility.php b/typo3/sysext/core/Classes/Utility/GeneralUtility.php index 64d357cd5ad4..670eecfdbaa8 100755 --- a/typo3/sysext/core/Classes/Utility/GeneralUtility.php +++ b/typo3/sysext/core/Classes/Utility/GeneralUtility.php @@ -1899,15 +1899,19 @@ class GeneralUtility { * * @param string $string XML data input * @param int $depth Number of element levels to resolve the XML into an array. Any further structure will be set as XML. + * @param array $parserOptions Options that will be passed to PHP's xml_parser_set_option() * @return mixed The array with the parsed structure unless the XML parser returns with an error in which case the error message string is returned. * @author bisqwit at iki dot fi dot not dot for dot ads dot invalid / http://dk.php.net/xml_parse_into_struct + kasperYYYY@typo3.com */ - static public function xml2tree($string, $depth = 999) { + static public function xml2tree($string, $depth = 999, $parserOptions = array()) { $parser = xml_parser_create(); $vals = array(); $index = array(); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0); + foreach ($parserOptions as $option => $value) { + xml_parser_set_option($parser, $option, $value); + } xml_parse_into_struct($parser, $string, $vals, $index); if (xml_get_error_code($parser)) { return 'Line ' . xml_get_current_line_number($parser) . ': ' . xml_error_string(xml_get_error_code($parser)); diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-59384-XMLParserOptionsForXml2tree.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-59384-XMLParserOptionsForXml2tree.rst new file mode 100644 index 000000000000..5ca843cb70ad --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Feature-59384-XMLParserOptionsForXml2tree.rst @@ -0,0 +1,18 @@ +=================================================== +Feature: #59384 - XML parser options for xml2tree() +=================================================== + +Description +=========== + +GeneralUtility::xml_parser_set_option() gets an optional parameter, an array, that can hold options for the parser. Those will simply be passed through to the PHP-function xml_parser_set_option(). + +.. code-block:: php + + GeneralUtility::xml2tree($xmlData, 999, array(XML_OPTION_SKIP_WHITE => 1)); + + +Impact +====== + +It's just an optional parameter. If you don't specify it simply no additional initialisation of the XML-parser will be done. -- GitLab