Issue
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.
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.
Solution
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.
Answered By - scsfdev
Answer Checked By - Candace Johnson (JavaFixing Volunteer)