diff --git a/typo3/sysext/core/Classes/Utility/GeneralUtility.php b/typo3/sysext/core/Classes/Utility/GeneralUtility.php
index 8ace260c8cf189e171e13b8ccab394add5433bee..d1f0f1936edb2491af88891f85e6f046a93b365e 100644
--- a/typo3/sysext/core/Classes/Utility/GeneralUtility.php
+++ b/typo3/sysext/core/Classes/Utility/GeneralUtility.php
@@ -1795,7 +1795,7 @@ class GeneralUtility
         if (!empty($firstLevelCache[$identifier])) {
             $array = $firstLevelCache[$identifier];
         } else {
-            $array = self::xml2arrayProcess($string, $NSprefix, $reportDocTag);
+            $array = self::xml2arrayProcess(trim($string), $NSprefix, $reportDocTag);
             // Store content in first level cache
             $firstLevelCache[$identifier] = $array;
         }
diff --git a/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php b/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php
index f431d716f7058d49e95342d1c243b32a7051934d..fc60703b6975bf18ec96b3bd23a84fcd9b6c192d 100644
--- a/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php
+++ b/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php
@@ -4631,6 +4631,76 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 </phparray>', $output);
     }
 
+    /**
+     * @return array
+     */
+    public function providerForXml2Array(): array
+    {
+        return [
+            'inputWithoutWhitespaces' => [
+                '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
+                <T3FlexForms>
+                    <data>
+                        <field index="settings.persistenceIdentifier">
+                            <value index="vDEF">egon</value>
+                        </field>
+                    </data>
+                </T3FlexForms>'
+            ],
+            'inputWithPrecedingWhitespaces' => [
+                '
+                <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
+                <T3FlexForms>
+                    <data>
+                        <field index="settings.persistenceIdentifier">
+                            <value index="vDEF">egon</value>
+                        </field>
+                    </data>
+                </T3FlexForms>'
+            ],
+            'inputWithTrailingWhitespaces' => [
+                '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
+                <T3FlexForms>
+                    <data>
+                        <field index="settings.persistenceIdentifier">
+                            <value index="vDEF">egon</value>
+                        </field>
+                    </data>
+                </T3FlexForms>
+                '
+            ],
+            'inputWithPrecedingAndTrailingWhitespaces' => [
+                '
+                <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
+                <T3FlexForms>
+                    <data>
+                        <field index="settings.persistenceIdentifier">
+                            <value index="vDEF">egon</value>
+                        </field>
+                    </data>
+                </T3FlexForms>
+                '
+            ],
+        ];
+    }
+
+    /**
+     * @test
+     * @dataProvider providerForXml2Array
+     * @param string $input
+     */
+    public function xml2ArrayDealsProperlyWithWhitespace(string $input)
+    {
+        $expected = [
+            'data' => [
+                'settings.persistenceIdentifier' => [
+                    'vDEF' => 'egon',
+                ]
+            ],
+        ];
+        $this->assertSame($expected, GeneralUtility::xml2array($input));
+    }
+
     /**
      * @test
      * @dataProvider idnaEncodeDataProvider