github.com/LanceLRQ/deer-common@v0.0.9-0.20210319081233-e8222ac018a8/utils/xml.go (about)

     1  package utils
     2  
     3  import (
     4  	"encoding/xml"
     5  	"strings"
     6  )
     7  
     8  func XMLStringObject(xmlStr string, obj interface{}) bool {
     9  	// for testlib
    10  	xmlStr = strings.Replace(xmlStr, "<?xml version=\"1.0\" encoding=\"windows-1251\"?>", "<?xml version=\"1.0\" encoding=\"utf-8\"?>", -1)
    11  	return XMLBytesObject([]byte(xmlStr), obj)
    12  }
    13  
    14  func XMLBytesObject(xmlStr []byte, obj interface{}) bool {
    15  	err := xml.Unmarshal(xmlStr, &obj)
    16  	if err != nil {
    17  		return false
    18  	} else {
    19  		return true
    20  	}
    21  }