https://kotlinlang.org logo
#announcements
Title
# announcements
l

louiscad

11/13/2019, 4:32 PM
Hi, I'm looking for your recommendations to parse a simple xml file that doesn't go deeper than 3 levels. Here's an example of the kind of files I'm going to parse: https://dl.google.com/dl/android/maven2/androidx/lifecycle/lifecycle-runtime/maven-metadata.xml In the end, I want to get a list of the available versions. Is there a light library that I should use, or is that overkill and I should just use Kotlin stdlib to do it? Thanks for your input!
e

Evan R.

11/13/2019, 4:41 PM
Looks like there are some Java libraries built-in that you can leverage: https://stackoverflow.com/a/5059312
l

louiscad

11/18/2019, 2:56 PM
Thanks for the input. I ended up using the stdlib only to parse the files in a basic but sufficient way with only 4 lines of code: https://github.com/jmfayard/buildSrcVersions/blob/e234168b6dc22b8084fc47d8d8328cb5bf056bac/refreshVersions/src/main/kotlin/de/fayard/versions/LatestVersionRetrieval.kt#L43-L47
m

Matteo Mirk

11/19/2019, 9:59 AM
Ok, good if it works for you, but remember that parsing context-free languages with string search/regex can be brittle, but works for very simple cases
👌 1