1

I'm writing an Android app which retrieves xml data from the server. For manipulating such data I use Retrofit-SimpleXmlConverter(http://simple.sourceforge.net/home.php, https://github.com/square/retrofit/tree/master/retrofit-converters/simplexml) pipeline. I need to get this list of transactions:

<?xml version="1.0"?>
<Transactions>
<Transaction>
    <Transaction_Time>12-01-2018</Transaction_Time>
    <Transaction_Bonuses>123.11</Transaction_Bonuses>
    <Summ>123.11</Summ>
    <Transaction_Type>12</Transaction_Type>
    <Dop_Info>BLOB Base64 data with cyrillic symbols</Dop_Info>
</Transaction>
<Transaction>
    <Transaction_Time>12-01-2018</Transaction_Time>
    <Transaction_Bonuses>123.11</Transaction_Bonuses>
    <Summ>123.11</Summ>
    <Transaction_Type>12</Transaction_Type>
    <Dop_Info>no/Dop_Info>
</Transaction>

My problem is that xml has tag with BASE-64 encoded xml. From encoded xml I need follow data:

<CHECK>
<LINE name="Name of dish", quantity="1", summ="123,5"></LINE>
<LINE name="Name of dish", quantity="1", summ="123,5"></LINE>
<LINE name="Name of dish", quantity="1", summ="123,5"></LINE>
</CHECK>

Data classes:

@Root(name = "Transactions")
data class Transactions @JvmOverloads constructor(
    @field:ElementList(inline = true, required = false)
    @param:ElementList(inline = true, required = false)
    val list: List<Transaction>? = null
) {

@Root(name = "Transaction")
data class Transaction @JvmOverloads constructor(
        @field:Element(name = "Transaction_Time")
        @param:Element(name = "Transaction_Time")
        var transactionTime: String? = null,

        @field:Element(name = "Transaction_Bonuses")
        @param:Element(name = "Transaction_Bonuses")
        val transactionBonuses: Double? = 0.0,

        @field:Element(name = "Summ")
        @param:Element(name = "Summ")
        val summ: Double? = 0.0,

        @field:Element(name = "Transaction_Type")
        @param:Element(name = "Transaction_Type")
        val transactionType: Int? = 0,

        @field:Element(name = "Dop_Info")
        @param:Element(name = "Dop_Info")
        val dopInfo: ByteArray ? = null
 ){
        @Root(name = "CHECK")
        data class Check @JvmOverloads constructor(
                @field:ElementList(inline = true, required = false)
                @param:ElementList(inline = true, required = false)
                @field:Path("CHECKDATA/CHECKLINES")
                @param:Path("Holders_Cards/Holder_Card/Card")
                val list: List<Line>? = null
        ){
                @Root(name = "LINE")
                data class Line @JvmOverloads constructor(
                        @field: Attribute(name = "name", required = false)
                        @param: Attribute(name = "name", required = false)
                        val name: String? = null,

                        @field: Attribute(name = "quantity", required=false)
                        @param: Attribute(name = "quantity", required=false)
                        val quantity: Int? = null,

                        @field: Attribute(name = "summ", required = false)
                        @param: Attribute(name = "summ", required = false)
                        val summ: Double? = null
                )
        }
}
}

At this point I'm confused - how can I correctly serialize the xml in the way I could get instead of blob-data Check model? What are next steps?

P.S For solution I tried to use guide from http://simple.sourceforge.net/download/stream/doc/tutorial/tutorial.php#callback but it didn't find anything helpful

AlexF
  • 387
  • 1
  • 4
  • 20
  • This isn't java, Why did you tag java? – SamHoque Oct 09 '18 at 20:48
  • I know that it's Kotlin. But SimpleXml framework is concerned with Java and was written on it – AlexF Oct 09 '18 at 20:52
  • Is there a reason why you are using SimpleXml instead of XMLPullParser provided by android? – SamHoque Oct 09 '18 at 20:53
  • It saves me a lot from boilerplate. With SImpleXMl you need only build annotated model and add converter to retrofit client. While For XmlPullParser you need to write a lot of code with nested loops fro every atribute/tag – AlexF Oct 09 '18 at 21:00

0 Answers0