diff --git a/parser/helpers.go b/parser/helpers.go index abdd071..aa8c366 100644 --- a/parser/helpers.go +++ b/parser/helpers.go @@ -21,6 +21,17 @@ import ( // it is common to see variables such as "{{config.docker.interface}}" var configMatchRegex = regexp.MustCompile(`{{\s?config\.([\w.-]+)\s?}}`) +// Regex to support modifying XML inline variable data using the config tools. This means +// you can pass a replacement of Root.Property='[value="testing"]' to get an XML node +// matching: +// +// +// +// +// +// noinspection RegExpRedundantEscape +var xmlValueMatchRegex = regexp.MustCompile(`^\[([\w]+)='(.*)'\]$`) + // Gets the []byte representation of a configuration file to be passed through to other // handler functions. If the file does not currently exist, it will be created. func readFileBytes(path string) ([]byte, error) { diff --git a/parser/parser.go b/parser/parser.go index 1bd8a05..eb33bdf 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -162,7 +162,14 @@ func (f *ConfigurationFile) parseXmlFile(path string) error { // Iterate over the elements we found and update their values. for _, element := range doc.FindElements(path) { - element.SetText(string(value)) + if xmlValueMatchRegex.Match(value) { + k := xmlValueMatchRegex.ReplaceAllString(string(value), "$1") + v := xmlValueMatchRegex.ReplaceAllString(string(value), "$2") + + element.CreateAttr(k, v) + } else { + element.SetText(string(value)) + } } }