Item names for XML output

I have been working on a REST query API that works quite nicely, but there is a problem. I have model attributes that are indeed arrays of values obtained through various operations. If I use numeric array keys, i.e. the PHP array is:

[

[indent][

[indent]‘attributeA’ => ‘A’,

  'attributeB' => ['B1','B2']

[/indent]]

[/indent]]

converting to XML I have:

<root>

[indent] <item>

  &lt;attributeA&gt;A&lt;/attributeA&gt;


  &lt;attributeB&gt;

[indent] <item>B1</item>

        &lt;item&gt;B2&lt;/item&gt;

[/indent] </attributeB>

</item>

[/indent]</root>

This translates into JSON as follows:

[

[indent] {

[indent] "attributeA": "A",

  &quot;attributeB&quot;: [

[indent] "B1",

     &quot;B2&quot;

[/indent] ]

[/indent] }

[/indent]]

which is what I want in JSON. However, if I want to have different element names in the XML array, say

<root>

[indent] <invoice>

  &lt;attributeA&gt;A&lt;/attributeA&gt;


  &lt;attributeB&gt;

[indent] <row>B1</row>

        &lt;row&gt;B2&lt;/row&gt;

[/indent] </attributeB>

</invoice>

[/indent]</root>

I cannot find a way of doing it because there is only one $itemTag in XMLResonseFormatter that is used whenever the incoming array has numeric keys. On the other hand, PHP associative arrays do not allow me to use the same key more than once because subsequent usages will overwrite the previous key.

There must be something obvious that I am missing… How should the response array be structured to get the same JSON as before but the latter XML?

Can anybody shed some light, please?

Unfortunately, there is no simple way for doing what you want. You need to expand XmlResponseFormatter class.

Yes, this is the same conclusion I arrived to after further research. Actually, it may just be easier to transform the resulting XML with a XSL template before returning it to the client.