Skip to content

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

Open

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>

Activity

  1. added this to the 1.2.0 Release milestone on Jul 24, 2017
  2. tyzoid commented on Oct 22, 2017

    @tyzoid
    CollaboratorAuthor

    Solution: Write a few generic API Response wrapper objects, which would allow correct exporting of both json, and xml.

    Now to write it up.

  3. added a commit that references this issue on Oct 22, 2017
  4. tyzoid commented on Nov 26, 2017

    @tyzoid
    CollaboratorAuthor

    Moving to version 1.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions