Answers for "golang read xml to struct"

0

golang read xml to struct

package main
 
import (
	"encoding/xml"
	"fmt"
	"io/ioutil"
)
 
type Notes struct {
	To      string `xml:"to"`
	From    string `xml:"from"`
	Heading string `xml:"heading"`
	Body    string `xml:"body"`
}
 
func main() {
	data, _ := ioutil.ReadFile("notes.xml")
 
	note := &Notes{}
 
	_ = xml.Unmarshal([]byte(data), ¬e)
 
	fmt.Println(note.To)
	fmt.Println(note.From)
	fmt.Println(note.Heading)
	fmt.Println(note.Body)
}
Posted by: Guest on April-13-2021

Browse Popular Code Answers by Language