How can I generate a XML request file with the structure below using Simple?
<?xml version="1.0" encoding="UTF-8"?>
<ft>
<request clientId="123" apiName="api_search_location_stops_nearby" apiVersion="2.0">
<client clientId="123"/>
<requestType>api_search_location_stops_nearby</requestType>
<outputCoords>WGS84</outputCoords>
<fromCoordName>WGS84</fromCoordName>
<fromType>coords</fromType>
<fromWgs84Lat>48.22</fromWgs84Lat>
<fromWgs84Lon>16.39</fromWgs84Lon>
</request>
</ft>
To generate the part <request> ... </request> is easy, but how can I add the XML open tag <?xml version="1.0" encoding="UTF-8"?> and the <ft> and the end tag </ft>?
If you are already able to generate the
<request>...</request>tag, I assume that you already have aRequestobject with the correct fields and so on, so in fact it is really simple..In order to generate the XML prolog you need to create your own
Formatter/Serializerwith theFormat(String)constructor: