2024-01-30 01:30:44 +08:00
|
|
|
package convutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/xml"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type XmlConvert struct{}
|
|
|
|
|
2024-02-20 10:55:46 +08:00
|
|
|
func (XmlConvert) Enable() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-01-30 01:30:44 +08:00
|
|
|
func (XmlConvert) Encode(str string) (string, bool) {
|
|
|
|
return str, true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (XmlConvert) Decode(str string) (string, bool) {
|
|
|
|
trimedStr := strings.TrimSpace(str)
|
|
|
|
if !strings.HasPrefix(trimedStr, "<") && !strings.HasSuffix(trimedStr, ">") {
|
|
|
|
return str, false
|
|
|
|
}
|
|
|
|
var obj any
|
|
|
|
err := xml.Unmarshal([]byte(trimedStr), &obj)
|
|
|
|
return str, err == nil
|
|
|
|
}
|