Search code examples
androidkotlinsimple-framework

How to parse a SOAP Response with SimpleXML in Android?


I need to read an XML file from a SOAP service in my android app and have a problem. The request object was no problem at all but when trying to read the response I do not get any elements.

The XML looks like

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
        <ns2:getTexts xmlns:ns2="http://service.......de/">
            <return>text1</return>
            <return>text2</return>
            <return>text3</return>
            <return>text4</return>
            <return>text5</return>
        </ns2:getTexts>
    </S:Body>
</S:Envelope>

My Modules are

@Root(name = "S:Envelope", strict = false)
class ResponseEnvelope @JvmOverloads constructor(
    @field:Element(name = "S:Body", required = false) var body: GetTexts? = null
)

@Root(name = "S:Body", strict = false)
class GetTexts @JvmOverloads constructor(
    @field:Element(name = "ns2:getTexts", required = false) var response: TextItem? = null
)

@Root(strict = false)
class TextItem @JvmOverloads constructor(
    @field:ElementList(
        name = "ns2:getTexts",
        entry = "return",
        inline = true,
        required = false
    ) var textList: List<String>? = mutableListOf()
)

When trying to access the ResponseEnvelope it is always null. Do I need to write a Converter for each class? Can somebody help me here please?


Solution

  • After a while I found out, that I do not need the prefixes to read the XML response. eg.

    @Root(name = "S:Envelope", strict = false) should be @Root(name = "Envelope", strict = false)