[#3896bk] Better support for XML documents
This commit is contained in:
parent
35cdff904f
commit
e1435bfe8f
|
@ -21,6 +21,17 @@ import (
|
||||||
// it is common to see variables such as "{{config.docker.interface}}"
|
// it is common to see variables such as "{{config.docker.interface}}"
|
||||||
var configMatchRegex = regexp.MustCompile(`{{\s?config\.([\w.-]+)\s?}}`)
|
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:
|
||||||
|
//
|
||||||
|
// <Root>
|
||||||
|
// <Property value="testing"/>
|
||||||
|
// </Root>
|
||||||
|
//
|
||||||
|
// noinspection RegExpRedundantEscape
|
||||||
|
var xmlValueMatchRegex = regexp.MustCompile(`^\[([\w]+)='(.*)'\]$`)
|
||||||
|
|
||||||
// Gets the []byte representation of a configuration file to be passed through to other
|
// 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.
|
// handler functions. If the file does not currently exist, it will be created.
|
||||||
func readFileBytes(path string) ([]byte, error) {
|
func readFileBytes(path string) ([]byte, error) {
|
||||||
|
|
|
@ -162,7 +162,14 @@ func (f *ConfigurationFile) parseXmlFile(path string) error {
|
||||||
|
|
||||||
// Iterate over the elements we found and update their values.
|
// Iterate over the elements we found and update their values.
|
||||||
for _, element := range doc.FindElements(path) {
|
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))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user