diff --git a/pkg/exchangerates/bank_of_israel_datasource.go b/pkg/exchangerates/bank_of_israel_datasource.go index e05a031c..d3e6e122 100644 --- a/pkg/exchangerates/bank_of_israel_datasource.go +++ b/pkg/exchangerates/bank_of_israel_datasource.go @@ -1,10 +1,13 @@ package exchangerates import ( + "bytes" "encoding/xml" "math" "time" + "golang.org/x/net/html/charset" + "github.com/mayswind/ezbookkeeping/pkg/core" "github.com/mayswind/ezbookkeeping/pkg/errs" "github.com/mayswind/ezbookkeeping/pkg/log" @@ -127,8 +130,11 @@ func (e *BankOfIsraelDataSource) GetRequestUrls() []string { // Parse returns the common response entity according to the bank of Israel data source raw response func (e *BankOfIsraelDataSource) Parse(c core.Context, content []byte) (*models.LatestExchangeRateResponse, error) { + xmlDecoder := xml.NewDecoder(bytes.NewReader(content)) + xmlDecoder.CharsetReader = charset.NewReaderLabel + bankOfIsraelData := &BankOfIsraelExchangeRateData{} - err := xml.Unmarshal(content, bankOfIsraelData) + err := xmlDecoder.Decode(bankOfIsraelData) if err != nil { log.Errorf(c, "[bank_of_israel_datasource.Parse] failed to parse xml data, content is %s, because %s", string(content), err.Error()) diff --git a/pkg/exchangerates/danmarks_national_bank_datasource.go b/pkg/exchangerates/danmarks_national_bank_datasource.go index b37edada..1abfee8e 100644 --- a/pkg/exchangerates/danmarks_national_bank_datasource.go +++ b/pkg/exchangerates/danmarks_national_bank_datasource.go @@ -1,10 +1,13 @@ package exchangerates import ( + "bytes" "encoding/xml" "math" "time" + "golang.org/x/net/html/charset" + "github.com/mayswind/ezbookkeeping/pkg/core" "github.com/mayswind/ezbookkeeping/pkg/errs" "github.com/mayswind/ezbookkeeping/pkg/log" @@ -135,8 +138,11 @@ func (e *DanmarksNationalbankDataSource) GetRequestUrls() []string { // Parse returns the common response entity according to the Danmarks Nationalbank data source raw response func (e *DanmarksNationalbankDataSource) Parse(c core.Context, content []byte) (*models.LatestExchangeRateResponse, error) { + xmlDecoder := xml.NewDecoder(bytes.NewReader(content)) + xmlDecoder.CharsetReader = charset.NewReaderLabel + danmarksNationalbankData := &DanmarksNationalbankExchangeRateData{} - err := xml.Unmarshal(content, danmarksNationalbankData) + err := xmlDecoder.Decode(danmarksNationalbankData) if err != nil { log.Errorf(c, "[danmarks_national_bank_datasource.Parse] failed to parse xml data, content is %s, because %s", string(content), err.Error()) diff --git a/pkg/exchangerates/euro_central_bank_datasource.go b/pkg/exchangerates/euro_central_bank_datasource.go index a9eda8d7..a55ead0a 100644 --- a/pkg/exchangerates/euro_central_bank_datasource.go +++ b/pkg/exchangerates/euro_central_bank_datasource.go @@ -1,9 +1,12 @@ package exchangerates import ( + "bytes" "encoding/xml" "time" + "golang.org/x/net/html/charset" + "github.com/mayswind/ezbookkeeping/pkg/core" "github.com/mayswind/ezbookkeeping/pkg/errs" "github.com/mayswind/ezbookkeeping/pkg/log" @@ -114,8 +117,11 @@ func (e *EuroCentralBankDataSource) GetRequestUrls() []string { // Parse returns the common response entity according to the euro central bank data source raw response func (e *EuroCentralBankDataSource) Parse(c core.Context, content []byte) (*models.LatestExchangeRateResponse, error) { + xmlDecoder := xml.NewDecoder(bytes.NewReader(content)) + xmlDecoder.CharsetReader = charset.NewReaderLabel + euroCentralBankData := &EuroCentralBankExchangeRateData{} - err := xml.Unmarshal(content, euroCentralBankData) + err := xmlDecoder.Decode(euroCentralBankData) if err != nil { log.Errorf(c, "[euro_central_bank_datasource.Parse] failed to parse xml data, content is %s, because %s", string(content), err.Error()) diff --git a/pkg/exchangerates/national_bank_of_poland_datasource.go b/pkg/exchangerates/national_bank_of_poland_datasource.go index fd8860e8..ea7e60b9 100644 --- a/pkg/exchangerates/national_bank_of_poland_datasource.go +++ b/pkg/exchangerates/national_bank_of_poland_datasource.go @@ -127,11 +127,11 @@ func (e *NationalBankOfPolandDataSource) GetRequestUrls() []string { // Parse returns the common response entity according to the National Bank of Poland data source raw response func (e *NationalBankOfPolandDataSource) Parse(c core.Context, content []byte) (*models.LatestExchangeRateResponse, error) { - nationalBankOfPolandData := &NationalBankOfPolandExchangeRateData{} - xmlDecoder := xml.NewDecoder(bytes.NewReader(content)) xmlDecoder.CharsetReader = charset.NewReaderLabel - err := xmlDecoder.Decode(&nationalBankOfPolandData) + + nationalBankOfPolandData := &NationalBankOfPolandExchangeRateData{} + err := xmlDecoder.Decode(nationalBankOfPolandData) if err != nil { log.Errorf(c, "[national_bank_of_poland_datasource.Parse] failed to parse xml data, content is %s, because %s", string(content), err.Error()) diff --git a/pkg/exchangerates/national_bank_of_romania_datasource.go b/pkg/exchangerates/national_bank_of_romania_datasource.go index fee4b62d..483b6800 100644 --- a/pkg/exchangerates/national_bank_of_romania_datasource.go +++ b/pkg/exchangerates/national_bank_of_romania_datasource.go @@ -1,10 +1,13 @@ package exchangerates import ( + "bytes" "encoding/xml" "math" "time" + "golang.org/x/net/html/charset" + "github.com/mayswind/ezbookkeeping/pkg/core" "github.com/mayswind/ezbookkeeping/pkg/errs" "github.com/mayswind/ezbookkeeping/pkg/log" @@ -163,8 +166,11 @@ func (e *NationalBankOfRomaniaDataSource) GetRequestUrls() []string { // Parse returns the common response entity according to the national bank of Romania data source raw response func (e *NationalBankOfRomaniaDataSource) Parse(c core.Context, content []byte) (*models.LatestExchangeRateResponse, error) { + xmlDecoder := xml.NewDecoder(bytes.NewReader(content)) + xmlDecoder.CharsetReader = charset.NewReaderLabel + nationalBankOfRomaniaData := &NationalBankOfRomaniaExchangeRateData{} - err := xml.Unmarshal(content, nationalBankOfRomaniaData) + err := xmlDecoder.Decode(nationalBankOfRomaniaData) if err != nil { log.Errorf(c, "[national_bank_of_romania_datasource.Parse] failed to parse xml data, content is %s, because %s", string(content), err.Error()) diff --git a/pkg/exchangerates/norges_bank_datasource.go b/pkg/exchangerates/norges_bank_datasource.go index 37cac009..43be8a27 100644 --- a/pkg/exchangerates/norges_bank_datasource.go +++ b/pkg/exchangerates/norges_bank_datasource.go @@ -1,10 +1,13 @@ package exchangerates import ( + "bytes" "encoding/xml" "math" "time" + "golang.org/x/net/html/charset" + "github.com/mayswind/ezbookkeeping/pkg/core" "github.com/mayswind/ezbookkeeping/pkg/errs" "github.com/mayswind/ezbookkeeping/pkg/log" @@ -159,8 +162,11 @@ func (e *NorgesBankDataSource) GetRequestUrls() []string { // Parse returns the common response entity according to the Norges Bank data source raw response func (e *NorgesBankDataSource) Parse(c core.Context, content []byte) (*models.LatestExchangeRateResponse, error) { + xmlDecoder := xml.NewDecoder(bytes.NewReader(content)) + xmlDecoder.CharsetReader = charset.NewReaderLabel + norgesBankData := &NorgesBankExchangeRateData{} - err := xml.Unmarshal(content, norgesBankData) + err := xmlDecoder.Decode(norgesBankData) if err != nil { log.Errorf(c, "[norges_bank_datasource.Parse] failed to parse xml data, content is %s, because %s", string(content), err.Error()) diff --git a/pkg/exchangerates/reserve_bank_of_australia_datasource.go b/pkg/exchangerates/reserve_bank_of_australia_datasource.go index 7dbd4f89..ff384415 100644 --- a/pkg/exchangerates/reserve_bank_of_australia_datasource.go +++ b/pkg/exchangerates/reserve_bank_of_australia_datasource.go @@ -1,9 +1,12 @@ package exchangerates import ( + "bytes" "encoding/xml" "time" + "golang.org/x/net/html/charset" + "github.com/mayswind/ezbookkeeping/pkg/core" "github.com/mayswind/ezbookkeeping/pkg/errs" "github.com/mayswind/ezbookkeeping/pkg/log" @@ -129,8 +132,11 @@ func (e *ReserveBankOfAustraliaDataSource) GetRequestUrls() []string { // Parse returns the common response entity according to the the reserve bank of Australia data source raw response func (e *ReserveBankOfAustraliaDataSource) Parse(c core.Context, content []byte) (*models.LatestExchangeRateResponse, error) { + xmlDecoder := xml.NewDecoder(bytes.NewReader(content)) + xmlDecoder.CharsetReader = charset.NewReaderLabel + reserveBankOfAustraliaData := &ReserveBankOfAustraliaData{} - err := xml.Unmarshal(content, reserveBankOfAustraliaData) + err := xmlDecoder.Decode(reserveBankOfAustraliaData) if err != nil { log.Errorf(c, "[reserve_bank_of_australia_datasource.Parse] failed to parse xml data, content is %s, because %s", string(content), err.Error()) diff --git a/pkg/exchangerates/swiss_national_bank_datasource.go b/pkg/exchangerates/swiss_national_bank_datasource.go index 44c511fe..69da8c1a 100644 --- a/pkg/exchangerates/swiss_national_bank_datasource.go +++ b/pkg/exchangerates/swiss_national_bank_datasource.go @@ -1,10 +1,13 @@ package exchangerates import ( + "bytes" "encoding/xml" "math" "time" + "golang.org/x/net/html/charset" + "github.com/mayswind/ezbookkeeping/pkg/core" "github.com/mayswind/ezbookkeeping/pkg/errs" "github.com/mayswind/ezbookkeeping/pkg/log" @@ -189,8 +192,11 @@ func (e *SwissNationalBankDataSource) GetRequestUrls() []string { // Parse returns the common response entity according to the the reserve Swiss National Bank data source raw response func (e *SwissNationalBankDataSource) Parse(c core.Context, content []byte) (*models.LatestExchangeRateResponse, error) { + xmlDecoder := xml.NewDecoder(bytes.NewReader(content)) + xmlDecoder.CharsetReader = charset.NewReaderLabel + swissNationalBankData := &SwissNationalBankData{} - err := xml.Unmarshal(content, swissNationalBankData) + err := xmlDecoder.Decode(swissNationalBankData) if err != nil { log.Errorf(c, "[swiss_national_bank_datasource.Parse] failed to parse xml data, content is %s, because %s", string(content), err.Error())