Can someone help me with this problem with retrofi...
# android
p
Can someone help me with this problem with retrofit and simplexml? I'm getting this exception:
Attribute does not have a match in class
Please, read this thread for the sample code.
not kotlin but kotlin colored 1
I need to parse a xml response from an api server with retrofit and simplexml. Having this XML:
Copy code
<metroStops>
    <num>1149</num>
    <list>
        <stopInfo>
            <id>1474</id>
            <name>
                <![CDATA[ Name1 ]]>
            </name>
            <name_it>
                <![CDATA[ ]]>
            </name_it>
            <mapplace x="-0.196916117820181" y="19.4457785932514"/>
            <york>0</york>
        </stopInfo>
        <stopInfo>
            <id>2241</id>
            <name>
                <![CDATA[ Name 2 ]]>
            </name>
            <name_it>
                <![CDATA[ ]]>
            </name_it>
            <mapplace x="-0.157938317042115" y="19.4504756799245"/>
            <york>0</york>
        </stopInfo>
    </list>
</metroStops>
And this data class model to parse with retrofit:
Copy code
data class MetroStops (
    val num: String,
    val list: List<stopInfo>
)

data class stopInfo (
    val id: String,
    val name: String,
    val name_it: String,
    val mapplace: mapplace,
    val york: String
)

data class mapplace (
    val x: String,
    val y: String
)
I got this error:
Copy code
Attribute 'x' does not have a match in class com.example.myapp.data.model.Mapplace
This is my retrofit initialization:
Copy code
Retrofit.Builder()
            .baseUrl("<https://www.mywebsite.com/>")
            .addConverterFactory(SimpleXmlConverterFactory.create())
            .build().create(MetroDataApiService::class.java)
Can someone help me solving this? Thanks
c
Check how to map XML attributes with the library you use.
K 1