Skip to content

XML Output not valid if returned array is not encapsulated #97

@tyzoid

Description

@tyzoid

The output tends to generate a XML document with more than one root node if the return values are not carefully encapsulated to avoid this.

One potential solution could be to detect the presence of multiple elements in the root array, and use a wrapping element to wrap them.

For comparison/testing, here is one such test case:
Controller:

class EmptyTest {
    /**
     * @name EmptyTest
     * @description Returns a bunch of empty/null values
     *
     * @url GET /empty
     */
    public function emptyTest() {
        return array(
            'message' => 'Hello World!',
            'test' => 0,
            'test2' => "0",
            'test3' => false,
            'text' => null,
            'string' => array(),
            'texts' => null,
            'strings' => array(),
            'arrs' => array('hi', 'hi2')
        );
    }
}

JSON:

{
    "message":"Hello World!",
    "test":0,
    "test2":"0",
    "test3":false,
    "text":null,
    "string":[],
    "texts":null,
    "strings":[],
    "arrs":[
        "hi",
        "hi2"
    ]
}

XML:

<?xml version="1.0"?>
<message>Hello World!</message>
<test>0</test>
<test2>0</test2>
<test3></test3>
<text></text>
<string></string>
<texts></texts>
<strings></strings>
<arrs>
    <arr>hi</arr>
    <arr>hi2</arr>
</arrs>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions