I want to do the following:
I want to use a YAML file to define what values to change in an XML file. Theoretically a match made in heaven but for how the detail works. Below code is wrong on several levels but it displays what I need. The thing is there is no way to walk the YAML file leaf by leaf, which I'd need here. So I need to resort to some yucky recursive stuff to strip out the "path".
The second problem is, that even if I have the path in a form "parent1[0].parent2[0].@description" I can't go xmlIn."${pathVariable}" = value because that only works on direct children.
#!/usr/bin/env groovy
// Test for YAML
import groovy.util.*
import groovy.text.*
import groovy.xml.*
@Grab('org.yaml:snakeyaml:1.18')
// YAML file
def yamlFile = '''"@description": "testParent1"
parent1[0]:
parent2[0]:
"@description": "testParent2"
'''
def xmlFile = '''
<root>
<parent1 description="test0">
<parent2 description="test1" />
</parent1>
<parent1>
<parent2 description="test2" />
</parent1>
</root>
'''
def config = new org.yaml.snakeyaml.Yaml().load(yamlFile)
def xmlIn = new XmlParser().parseText(xmlFile)
config.each {
println "${it.key} = ${it.value}"
xmlIn."${it.key}" = it.value
}