# XML response serialization for RESTful web service

**URL:** <https://forum.servoy.com/t/xml-response-serialization-for-restful-web-service/21042>\
**Category:** Questions\
**Created:** [July 27, 2023, 4:38pm UTC](https://forum.servoy.com/t/xml-response-serialization-for-restful-web-service/21042 "2023-07-27T16:38:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ATrinkunas](https://avatars.discourse-cdn.com/v4/letter/a/b19c9b/32.png) [@ATrinkunas](https://forum.servoy.com/u/ATrinkunas)\
**Post date:** [July 27, 2023, 4:38pm UTC](https://forum.servoy.com/t/xml-response-serialization-for-restful-web-service/21042/1 "2023-07-27T16:38:44Z")

</div>

Hi

RESTful web service response return value is a JavaScript object. This JavaScript object is serialized and placed in the body of the HTTP Response.  
Is there way somehow to control this serialization process?  
I want the attributes of this JavaScript object to be serialized to XML attributes (Not XML Elements)

Example:

JSON response:

```auto
{
    "JMF": {
        "Response": {
            "Type": "SubmissionMethods",
            "ReturnCode": "0",
            "ID": "SubmissionMethodsResponse_Q38BE5CF9-F912-4E18-8F76-C3DB8B9CEEE2",
            "refID": "Q38BE5CF9-F912-4E18-8F76-C3DB8B9CEEE2",
            "SubmissionMethods": {
                "Packaging": "MIME",
                "URLSchemes": "file http"
            }
        }
    }
}

```

XML Response:

```auto
<?xml version="1.0" encoding="UTF-8"?>
<JMF>
    <Response>
        <Type>SubmissionMethods</Type>
        <ReturnCode>0</ReturnCode>
        <ID>SubmissionMethodsResponse_Q38BE5CF9-F912-4E18-8F76-C3DB8B9CEEE2</ID>
        <refID>Q38BE5CF9-F912-4E18-8F76-C3DB8B9CEEE2</refID>
        <SubmissionMethods>
            <Packaging>MIME</Packaging>
            <URLSchemes>file http</URLSchemes>
        </SubmissionMethods>
    </Response>
</JMF>

```

I want “MIME” to be an attribute of “SubmissionMethods” XML Element etc.

Thanks, Anton

---

<div class="post-metadata">

**Author:** ![rgansevles](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@rgansevles](https://forum.servoy.com/u/rgansevles)\
**Post date:** [August 4, 2023, 9:45am UTC](https://forum.servoy.com/t/xml-response-serialization-for-restful-web-service/21042/2 "2023-08-04T09:45:20Z")

</div>

Hi,

In stead of a json object you can also return an xml object where you have full control of which data is serialized as element or as attribute:

```auto
return new XML('<JMF>\
    <Response>\
        <Type>SubmissionMethods</Type>\
        <ReturnCode>0</ReturnCode>\
        <ID>SubmissionMethodsResponse_Q38BE5CF9-F912-4E18-8F76-C3DB8B9CEEE2</ID>\
        <refID>Q38BE5CF9-F912-4E18-8F76-C3DB8B9CEEE2</refID>\
        <SubmissionMethods Packaging="MIME">\
            <URLSchemes>file http</URLSchemes>\
        </SubmissionMethods>\
    </Response>\
</JMF>')

```

Alternatively, you can create the xml programatically:

```auto
var xml = new XML('<JMF></JMF>')
xml.Response.Type = 'SubmissionMethods'
xml.Response.ReturnCode = 0
xml.Response.ID = 'SubmissionMethodsResponse_Q38BE5CF9-F912-4E18-8F76-C3DB8B9CEEE2'
xml.Response.refID = 'Q38BE5CF9-F912-4E18-8F76-C3DB8B9CEEE2'
xml.Response.SubmissionMethods.@Packaging = 'MIME'
xml.Response.SubmissionMethods.URLSchemes = 'file http'
return xml

```

In both cases, this is what is returned to the client:

```auto
<?xml version="1.0" encoding="UTF-8"?>
<JMF>
  <Response>
    <Type>SubmissionMethods</Type>
    <ReturnCode>0</ReturnCode>
    <ID>SubmissionMethodsResponse_Q38BE5CF9-F912-4E18-8F76-C3DB8B9CEEE2</ID>
    <refID>Q38BE5CF9-F912-4E18-8F76-C3DB8B9CEEE2</refID>
    <SubmissionMethods Packaging="MIME">
      <URLSchemes>file http</URLSchemes>
    </SubmissionMethods>
  </Response>
</JMF>

```
