diff --git a/lesson7/marshalling/13_xml_marshal_array_of_struct_3.go b/lesson7/marshalling/13_xml_marshal_array_of_struct_3.go new file mode 100644 index 0000000..3b4cc2f --- /dev/null +++ b/lesson7/marshalling/13_xml_marshal_array_of_struct_3.go @@ -0,0 +1,40 @@ +package main + +import ( + "encoding/xml" + "fmt" +) + +type User struct { + XMLName xml.Name `xml:"user"` + Id uint32 `xml:"id"` + Name string `xml:"user_name"` + Surname string `xml:"surname"` +} + +type Users struct { + XMLName xml.Name `xml:"users"` + List []User +} + +func main() { + var users Users = Users{ + List: []User{ + User{ + Id: 1, + Name: "Pepek", + Surname: "Vyskoč"}, + User{ + Id: 2, + Name: "Pepek", + Surname: "Vyskoč"}, + User{ + Id: 3, + Name: "Josef", + Surname: "Vyskočil"}, + }, + } + + usersAsXML, _ := xml.MarshalIndent(users, "", " ") + fmt.Println(string(usersAsXML)) +}