@@ -59,6 +59,7 @@ class XmlEncoder implements EncoderInterface, DecoderInterface, NormalizationAwa
5959 public const TYPE_CAST_ATTRIBUTES = 'xml_type_cast_attributes ' ;
6060 public const VERSION = 'xml_version ' ;
6161 public const CDATA_WRAPPING = 'cdata_wrapping ' ;
62+ public const ARRAY_AS_ITEM = 'array_as_item ' ;
6263 public const CDATA_WRAPPING_PATTERN = 'cdata_wrapping_pattern ' ;
6364 public const IGNORE_EMPTY_ATTRIBUTES = 'ignore_empty_attributes ' ;
6465
@@ -71,6 +72,7 @@ class XmlEncoder implements EncoderInterface, DecoderInterface, NormalizationAwa
7172 self ::REMOVE_EMPTY_TAGS => false ,
7273 self ::ROOT_NODE_NAME => 'response ' ,
7374 self ::TYPE_CAST_ATTRIBUTES => true ,
75+ self ::ARRAY_AS_ITEM => false ,
7476 self ::CDATA_WRAPPING => true ,
7577 self ::CDATA_WRAPPING_PATTERN => '/[<>&]/ ' ,
7678 self ::IGNORE_EMPTY_ATTRIBUTES => false ,
@@ -345,6 +347,7 @@ private function buildXml(\DOMNode $parentNode, mixed $data, string $format, arr
345347 {
346348 $ append = true ;
347349 $ removeEmptyTags = $ context [self ::REMOVE_EMPTY_TAGS ] ?? $ this ->defaultContext [self ::REMOVE_EMPTY_TAGS ] ?? false ;
350+ $ listAsChildren = $ context [self ::ARRAY_AS_ITEM ] ?? $ this ->defaultContext [self ::ARRAY_AS_ITEM ] ?? false ;
348351 $ encoderIgnoredNodeTypes = $ context [self ::ENCODER_IGNORED_NODE_TYPES ] ?? $ this ->defaultContext [self ::ENCODER_IGNORED_NODE_TYPES ];
349352
350353 if (\is_array ($ data ) || ($ data instanceof \Traversable && (null === $ this ->serializer || !$ this ->serializer ->supportsNormalization ($ data , $ format )))) {
@@ -373,7 +376,7 @@ private function buildXml(\DOMNode $parentNode, mixed $data, string $format, arr
373376 }
374377 } elseif (\is_array ($ data ) && false === is_numeric ($ key )) {
375378 // Is this array fully numeric keys?
376- if (ctype_digit (implode ('' , array_keys ($ data )))) {
379+ if (! $ listAsChildren && ctype_digit (implode ('' , array_keys ($ data )))) {
377380 /*
378381 * Create nodes to append to $parentNode based on the $key of this array
379382 * Produces <xml><item>0</item><item>1</item></xml>
0 commit comments