Skip to content

Commit

Permalink
Example #5: marshal structs to XML with specifying node names
Browse files Browse the repository at this point in the history
  • Loading branch information
tisnik committed Jul 1, 2020
1 parent 76e401f commit 38b7da5
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions lesson7/marshalling/05_xml_marshal_struct_2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"encoding/xml"
"fmt"
)

type User1 struct {
id uint32 `xml:"id"`
name string `xml:"user_name"`
surname string `xml:"surname"`
}

type User2 struct {
Id uint32 `xml:"id"`
Name string `xml:"user_name"`
Surname string `xml:"surname"`
}

func main() {
user1 := User1{
1,
"Pepek",
"Vyskoč"}

user2 := User2{
1,
"Pepek",
"Vyskoč"}

user1asXML, _ := xml.Marshal(user1)
fmt.Println(string(user1asXML))

fmt.Println()

user2asXML, _ := xml.Marshal(user2)
fmt.Println(string(user2asXML))
}

0 comments on commit 38b7da5

Please sign in to comment.