【发布时间】:2016-06-20 13:36:23
【问题描述】:
嗨,我的 groovy 脚本从文件中删除一个 xml 标记并写入文件。
import org.apache.commons.lang.RandomStringUtils
import groovy.util.XmlSlurper
inputFile = 'C:\\sample.xml'
outputFile = 'C:\\ouput.txt'
XMLTag='Details'
fileContents = new File(inputFile).getText('UTF-8')
def xmlFile=new XmlSlurper().parseText(fileContents)
def myPayload= new String(xmlFile.'**'.find{node-> node.name() == XMLTag} *.text().toString())
file = new File(outputFile)
w = file.newWriter()
w << myPayload.substring(1, myPayload.length()-1)
w.close()
我的问题是如何编写它,以便它遍历整个目录并在多个 xml 文件上执行它并创建多个输出,因为它是硬编码的。 ('C:\sample.xml' 和 'C:\ouput.txt')
谢谢
里昂
【问题讨论】: