I have a code such as:
<?php
class Files {
protected function get() {
return array(
'files' => array(
'file' => array(
array(
'filename' => 'test1.jpg',
'modified' => '2015-01-01 00:00:00',
),
array(
'filename' => 'test2.jpg',
'modified' => '2015-01-02 00:00:00',
),
array(
'filename' => 'test3.jpg',
'modified' => '2015-01-03 00:00:00',
),
),
)
);
}
}
The JSON output is:
{
"files": {
"file": [
{
"filename": "test1.jpg",
"modified": "2015-01-01 00:00:00"
},
{
"filename": "test2.jpg",
"modified": "2015-01-02 00:00:00"
},
{
"filename": "test3.jpg",
"modified": "2015-01-03 00:00:00"
}
]
}
}
XML output:
<response>
<files>
<file>
<item>
<filename>test1.jpg</filename>
<modified>2015-01-01 00:00:00</modified>
</item>
<item>
<filename>test2.jpg</filename>
<modified>2015-01-02 00:00:00</modified>
</item>
<item>
<filename>test3.jpg</filename>
<modified>2015-01-03 00:00:00</modified>
</item>
</file>
</files>
</response>
Problem is that I want the files to be within <file>
tags, not within <item>
tags.
Here is an example XML output I would like to get:
<response>
<files>
<file>
<filename>test1.jpg</filename>
<modified>2015-01-01 00:00:00</modified>
</file>
<file>
<filename>test2.jpg</filename>
<modified>2015-01-02 00:00:00</modified>
</file>
<file>
<filename>test3.jpg</filename>
<modified>2015-01-03 00:00:00</modified>
</file>
</files>
</response>
How can I achieve this? I've tried pretty much everything I possibly could come up with, with no luck.
I tried the following answer, but it didn't help. I guess the answer is for Restler 1 or 2, since it's so old: Luracast Restler: "Naming" returned objects
EDIT:
Changing the XmlFormat::$defaultTagName = 'file';
or something like that is not an option, since I need to rename other <item>
tags also in the same request.
EDIT 2:
I know this can be achieved by creating my very own "XmlFormat.php" file with a format that I want to have, but does the current original support this kind of customisation like it used to (according to this answer: Luracast Restler: "Naming" returned objects) or is this feature been removed later on?