looking for something like xmlslurper (groovy) for...
# announcements
t
looking for something like xmlslurper (groovy) for kotlin. Kotlin XML Binding (http://jonnyzzz.com/blog/2016/01/06/kotlin-xml/) seems useable. Opinions? Need to figure out how to parse an XML string into an object too using this lib..
k
the git repo shows (sort of) how to parse them (https://github.com/jonnyzzz/kotlin.xml.bind), this one looks cleaner tho imo: https://github.com/kongsin/KotlinXMLParser
but if you can, you should use json instead
t
Thanks. json sure, but not an option - rewrite of a legacy system very xml centric..
k
as in xml setting files only used server side, or client provided xml files
because if it's all hidden it might be beneficial to switch to json, and maybe for now temporarily provide legacy xml support
t
it’s GSRL7 xml files server side as specified by Dun & Bradstreet our partner. Nothing much to do about it 😉
Finally did it like this, there might be other ways..
Copy code
val operationMetadata = JDOM.load(parseXml(messageText), OperationMetadata::class.java)

    private fun parseXml(messageText: String): Element {
        val saxBuilder = SAXBuilder()
        return saxBuilder.build(messageText.reader()).rootElement
    }
t
thanks, will check it out 🙂
234 Views