REST V2 Connector > Introduction to REST V2 Connector > XML objects in swagger specification
  

XML objects in swagger specification

You can configure XML objects such as XML attributes, the wrapper object, and the namespace object in the swagger specification file.
You can define attributes only for XML objects. You cannot define attributes for XML elements. You can use wrapper objects for a simple type array element only when the array element has inline definitions. Use qualified and unqualified namespace objects in response for source, midstream, and target transformations and in request for midstream and target transformations.
An XML attribute is always of type string. Even if the swagger definition has attribute with type as number, REST V2 Connector always treats the attribute as string. The XSD generated contains the data type as string for the XML attribute.
Note: Ensure that the Swagger definition does not contain multiple namespaces.
Swagger definition for an XML attribute:
"XMLAttrArray_Request##body##Employee##dep##Mangr" : {
"properties" : {
"desg" : {
"type" : "string",
"xml": { "attribute": true }
}, "mid" : { "type" : "string" },
XML attribute sample:
<dep>
<Mangr desg="Director">
<mid>em09</mid>
<mname>mg</mname>
</Mangr>
<id>did</id>
<name>dname</name>
</dep>
Note: If the REST endpoint returns a response in an application/xml format and the XML element in the response contains both an attribute and an element value, the mapping does not process the response. For example, you cannot process an XML sample <emp desg="Director">John</emp>, where the emp element contains both an attribute desg and an element value John.
Swagger definition for a Wrapper object:
"books" : {
"type" : "array",
"items" : { "type" : "string" },
"xml": {
"wrapped" : "true", "name": "books-array"
}
}
Wrapper object sample:
<books-array>
<books>1</books>
<books>2</books>
</books-array>
Swagger definition for a Namespace object:
root" : {
"properties" : {
"table" : {
"$ref" : "#/definitions/NSResReq_Request##body##root##table"
}
},
"xml":{
"prefix": "h",
"namespace": "http://www.w3.org/TR/html4/"
}
}
Namespace object sample:
<h:root xmlns:h="http://www.w3.org/TR/html4/">
<table>
<tr>
<td>Apples</td>
<td>Bananas</td>
</tr>
</table>
</h:root>