This content originally appeared on DEV Community and was authored by Sheeraz Ahmed Memon
Introduction:
In 2021, Lots of APIs are written using JSON. But there are some API in some domains like healthcare, traveling and web streaming that return XML. XML is a terrible serialization format, it wasn’t initially, but has been misused for decades and abused by many a software development engineer out in the wild.
When you want to interact with one of these XML, you might cry or shake your fist initially.
But no more.
We can now use Simple XML library in Kotlin that does the heavy load, parses XML and gives the POJO (Plain old java object) magically.
Steps:
So here is the XML we will use in this example, and parse it
- First add Simple XML library in Gradle.
- Now let's create POJO’s
- Now that POJO’s are created, we can parse it using the following code
val serializer: Serializer = Persister() val dataFetch = serializer.read(DataFetch::class.java, xmlToParse)
- Easy, right, here is a test to check the parsing.
How to Parse XML using Kotlin in 2021 | by Sheeraz Ahmed Memon | Dec, 2021 | Medium
Sheeraz Ahmed Memon ・ ・
sheerazmemonway.Medium
This content originally appeared on DEV Community and was authored by Sheeraz Ahmed Memon
Sheeraz Ahmed Memon | Sciencx (2021-12-04T13:56:53+00:00) How to Parse XML using Kotlin in 2021. Retrieved from https://www.scien.cx/2021/12/04/how-to-parse-xml-using-kotlin-in-2021/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.