Hi am new to android programming i have gone through some links for how to parse the XML response using retrofit and i tried for below XML as shown.
Is there any necessa
For example you have an XML string:
<Response>
<Field1>string</Field1>
<Field2>string</Field2>
<Field3>string</Field3>
<Field4>string</Field4>
</Response>
First, add to your gradle
file:
implementation "com.squareup.retrofit2:converter-simplexml:2.6.1"
Next, add to your retrofit
builder:
.addConverterFactory(SimpleXmlConverterFactory.create())
Note: SimpleXmlConverterFactory
is deprecated now, but I've not found a better solution
And your model class:
@Root(name = "Response")
data class Response @JvmOverloads constructor(
@field:Element(name = "Field1")
var bucket: String = "",
@field:Element(name = "Field2")
var key: String = "",
@field:Element(name = "Field3")
var etag: String = "",
@field:Element(name = "Field4")
var location: String = ""
)
Note: properties need to be predefined
Your ApiService
file will be the same as you are parsing json