-1

I would like to know how to read XML on Android without using XMLPullParser. I already tried XMLPullParser from this link https://developer.android.com/training/basics/network-ops/xml.html. It is working. It just due to my requirements, I need to read web service returns XML data in "String format" and do the processing later (not at the time I connect to HttpUrlConnection).

Right now, I am using below code and it is reading all XML data correctly except URL link in "link" tag.

    val inputStream = urlCon.inputStream
    reader = BufferedReader(InputStreamReader(inputStream))

    builder = StringBuilder()
    var line: String? = reader.readLine()
    while (line != null) {
        builder.append(line)
        builder.append("\n")
        line = reader.readLine()
    }


Here is the return XML that I got from above.
XML return from BufferedReader


By right, it should be in this https://internalws.factory.com/wh/entry?requestID=admin&id=TD12011101 format.

Any suggestion (java or Kotlin is ok for me) on my reading part? Thanks.

scsfdev
  • 333
  • 1
  • 5
  • 13

1 Answers1

0

For some reason, someone down-vote my question. I cannot find any reason that deserves a down-vote.
Since I am still learning in Android programming, for such question, it may seem easy for those who are doing the coding in Android (or Java or Kotlin, whatever). For me, this issue is a headache.

Anyway, after spending a few days, I managed to find the answer.
Previously, I was too focus in UrlDecoder that's why I could not find a correct answer.

Actually the return was in Html Code format, I need to convert this Html code to normal readable string by using Html.fromHtml.

From this post, I got my answer >> https://stackoverflow.com/a/40871051/770989

It also explains on how to use it correctly since this function is deprecated after API v24.

scsfdev
  • 333
  • 1
  • 5
  • 13