美文网首页
Android-Groovy-string.xml-增删改查-简

Android-Groovy-string.xml-增删改查-简

作者: 晖仔Milo | 来源:发表于2022-07-18 15:25 被阅读0次

    废话不多说,直接上代码

    如何查询

        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()
    

    相关文章

      网友评论

          本文标题:Android-Groovy-string.xml-增删改查-简

          本文链接:https://www.haomeiwen.com/subject/qchdirtx.html