M/DB:X Response Structure

M/DB:X responses take the form of either XML documents or JSON strings. XML is the default output format, but by simply adding the name/value pair OutputFormat=JSON to an M/DB:X HTTP request, the response will be automatically formatted as a corresponding JSON object string.

XML responses are returned as Content-type: text/xml. JSON responses are returned as Content-type: application/json.

There are two types of responses possible from M/DB:X:

Error Responses

All error responses follow the pattern of the example below:

XML format:

<?xml version='1.0'?>
<Response>
   <Errors>
      <Error>
         <Code>
            InvalidDocumentName
         </Code>
         <Message>
            Non-existent or Invalid Document Name
         </Message>
         <BoxUsage>
            0
         </BoxUsage>
      </Error>
   </Errors>
   <RequestId>
      7a79c058-f8f1-63b8-5632-ce0873b57633
   </RequestId>
</Response>

JSON format:

{ErrorCode:"InvalidDocumentName",ErrorMessage:"Non-existent or Invalid DocumentName"}

The two key pieces of information are the error code and message.

Correct Responses

The actual content from M/DB:X Actions varies from Action to Action, but the overall structure is typified by the following example, typical outout from the ListDOMs action:

XML Format

<?xml version='1.0'?>
<ListDOMsResponse xmlns="http://mdbx.mgateway.com/doc/2009-06-05/">
   <ListDOMsResult>
      <DOM>
         <DocumentName>
            MDBXTest
         </DocumentName>
         <DocumentNode>
            1-1
         </DocumentNode>
      </DOM>
      <DOM>
         <DocumentName>
            example
         </DocumentName>
         <DocumentNode>
            5-1
         </DocumentNode>
      </DOM>
   </ListDOMsResult>
</ListDOMsResponse>

Almost all of the XML responses from M/DB:X Actions have an outer element named ActionResponse with a namespace of http://mdbx.mgateway.com/doc/2009-06-05/, with the response content further wrappered by an element named ActionResult. Those familiar with SimpleDB will recognise this pattern.

The main exception to this M/DB:X XML formatting pattern is the outputDOM Action which outputs the specified XML document without any added XML container or wrapper.

JSON format

[{DocumentName:"MDBXTest",DocumentOID:"1-1"},{DocumentName:"example",DocumentOID:"5-1"}]

In this case, the response is a JSON array of objects. In other APIs, a JSON object is returned, eg:

{NodeOID:"5-3",NodeType:1}

If you use the OutputJSON Action, M/DB:X will automatically convert the specified XML DOM into a corresponding JSON object, eg:

{rob:{span:{div:null,jsonTest:{x1:"testing",param2:"hello",#text:"This is an example"},
jsonTest2:[{x1:"testing",#text:"This is an example"},{x1:"testing",#text:"This is an example"},
{x1:"testing",#text:"This is an example"},{x1:"testing",#text:"This is an example"}],
myNewTag:[{a:"hello",b:"234",#text:"world"},{a:"hello",b:"234",#text:"world"},
{a:"hello",b:"234",#text:"world"},{a:"hello",b:"234",#text:"world"}],
myNewTag2:{a:"helloxxx",b:"234555",id:"rob1",#text:"world"},robnew1:{span:"hello world!"},span:null}}}

Note that M/DB:X can convert an XML DOM to JSON format irrespective of how the DOM was created: it is not restricted to DOMs that were created from JSON input.