seems to work
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-09-28 14:27:03 +10:00
parent 95a48a89a6
commit 6c7d447c56
6 changed files with 162 additions and 61 deletions

View File

@@ -23,7 +23,7 @@ import (
// As of now XML marshaling in Go always uses start and end tags,
// which results in XML elements like the one below.
//
// <Person name="me"></Person>
// <Person name="me"></Person>
//
// Above XML elements cannot be parsed by the remote Cisco UCS API endpoint,
// and such API calls result in parse error returned to the client.
@@ -41,13 +41,15 @@ import (
// hopefully one day make into the language as a feature.
//
// https://groups.google.com/forum/#!topic/golang-nuts/guG6iOCRu08
//
// Update by Nathan: update regex to also match caret when searching for tags to update
func xmlMarshalWithSelfClosingTags(in interface{}) ([]byte, error) {
data, err := xml.Marshal(in)
if err != nil {
return nil, err
}
re := regexp.MustCompile(`<([^/][\w\s\"\=\-\/]*)>\s*<(\/\w*)>`)
re := regexp.MustCompile(`<([^/][\w\s\"\=\-\/\^]*)>\s*<(\/\w*)>`)
newData := re.ReplaceAllString(string(data), "<$1/>")
return []byte(newData), nil