Kotlin replacement for groovy XmlSlurper & MarkupBuilder

I thought I would replace groovy with Kotlin in our gradle scripts for our Android project, so I could start learning Kotlin, but the first problem I ran into was trying to hunt down some classes or libraries that could replace XmlSlurper and MarkupBuilder ... Can anyone suggest a library or class to use?

def entries = new XmlSlurper().parse("${projectDir}/src/release/res/values/app_settings.xml")
    def fileLocation = "${projectDir}/src/debug/res/xml/env_prod.xml"
    println "XML file location = ${fileLocation}"
    def writer = new FileWriter(new File(fileLocation))
    def xmlOut = new MarkupBuilder(writer)
    xmlOut.mkp.xmlDeclaration(version: "1.0", encoding: "utf-8")
    xmlOut.Environment {
        entries.string.each {
            def name = it.@name.toString()
            def body = it.text()
            if (name.startsWith('default_')) {
                // don't copy production omniture when we're doing local testing!
                name = name.replace('default_', '').toUpperCase()
                xmlOut.entry(['name' : name], body)
            }
        }
    }

      

+3


source to share





All Articles