diff --git a/encode.go b/encode.go index 8487ea0..fa2c551 100644 --- a/encode.go +++ b/encode.go @@ -4,6 +4,7 @@ import ( "encoding/xml" "fmt" "reflect" + "strings" ) var ( @@ -108,7 +109,24 @@ func (tokens *tokenData) recursiveEncode(hm interface{}) { content := xml.CharData(v.String()) tokens.data = append(tokens.data, content) case reflect.Struct: - tokens.data = append(tokens.data, v.Interface()) + for i := 0; i < v.NumField(); i++ { + field := v.Field(i) + var name string + name = v.Type().Field(i).Tag.Get("xml") + if name == "" { + name = v.Type().Field(i).Name + name = strings.ToLower(name[0:1]) + name[1:] + } + t := xml.StartElement{ + Name: xml.Name{ + Space: "", + Local: name, + }, + } + tokens.data = append(tokens.data, t) + tokens.recursiveEncode(field.Interface()) + tokens.data = append(tokens.data, xml.EndElement{Name: t.Name}) + } } } diff --git a/soap_test.go b/soap_test.go index 90481b2..7c9c570 100644 --- a/soap_test.go +++ b/soap_test.go @@ -68,10 +68,7 @@ type CheckVatRequest struct { } func (r CheckVatRequest) SoapBuildRequest() *Request { - return NewRequest("checkVat", Params{ - "countryCode": r.CountryCode, - "vatNumber": r.VatNumber, - }) + return NewRequest("checkVat", r) } type CheckVatResponse struct {