首页 > 解决方案 > Golang XML 编码

问题描述

如何在 Go 语言中使用 Windows 1250 编码解析 XML?

package main

import (
    "encoding/xml"
    "fmt"
    "io/ioutil"
    "os"
)

// Regions comment
type Regions struct {
    XMLName    xml.Name `xml:"CNUMNUTS"`
    RegionList []Region `xml:"CNUMNUTS_ROW"`
}

// Region comment
type Region struct {
    XMLName   xml.Name `xml:"CNUMNUTS_ROW"`
    Nazevnuts string   `xml:"NAZEVNUTS"`
    Numnuts   string   `xml:"NUMNUTS"`
    Nuts      string   `xml:"NUTS"`
    Kodcis    string   `xml:"KODCIS"`
    Chodnota  string   `xml:"CHODNOTA"`
}

func main() {

    xmlFile, _ := os.Open("cnumnuts.xml")
    defer xmlFile.Close()

    byteValue, _ := ioutil.ReadAll(xmlFile)

    var regions Regions

    xml.Unmarshal(byteValue, &regions)

}

我在 Windows 64bit 上使用 Go 1.13.7

谢谢

标签: xmlparsinggo

解决方案


推荐阅读