Android-Groovy-string.xml-增删改查-简
2022-07-18 本文已影响0人
晖仔Milo
废话不多说,直接上代码
如何查询
def xmlReader = new XmlSlurper().parse(inputFile)
xmlReader.children().each {
println("key == ${it.@name}, value == ${it.text()}")
}
Node inputNode = openXml(inputFile)
inputNode.children().each {
println(it.attributes()["name"] + ", " + it.text())
}
static def openXml(xml) {
def xmlParser = new groovy.util.XmlParser()
def result = xmlParser.parse(xml)
return result
}
如何删除
for (i in 0..<delList.size()) {
inputNode.remove(delList.get(i))
}
PrintWriter inputWriter = new PrintWriter(inputFile)
inputWriter.write(XmlUtil.serialize(inputNode))
inputWriter.close()