xml - Golang XML 编码
问题描述
如何在 Go 语言中使用 Windows 1250 编码解析 XML?
<?xml version="1.0" encoding="utf-8"?>
下面的代码在 XML 文件中可以正常工作。- 代码不适
<?xml version="1.0" encoding="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, ®ions)
}
我在 Windows 64bit 上使用 Go 1.13.7
谢谢
解决方案
推荐阅读
- symfony - 用一个表单修改多个实体(批量编辑)
- java - 如何为我的 JTextArea 添加 JScrollPane?
- r - 重新排列表格中的值
- javascript - jQuery在分页中全选不起作用
- ajax - Ajax 不适用于 laravel 项目部署
- java - 生成 Hibernate 映射文件时未创建注释
- android - 膨胀类 com.mancj.materialsearchbar.MaterialSearchBar 时出错
- java - 通过 Dagger 将 Presenter 注入到活动中
- linux - 在 Linux Mate / Ubuntu 上以编程方式切换应用程序全屏模式
- linux - 如何在 bash 中停止通过 ctrl+c 终止脚本?