This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user