This commit is contained in:
Sangeeth Sudheer 2024-05-02 13:12:12 +05:30
parent f042da5479
commit b1fe04a282
Signed by: x
GPG Key ID: F6D06ECE734C57D1
2 changed files with 30 additions and 2 deletions

View File

@ -26,7 +26,8 @@ package main
// import "git.sangeeth.dev/gobyexample/formatting" // import "git.sangeeth.dev/gobyexample/formatting"
// import "git.sangeeth.dev/gobyexample/templates" // import "git.sangeeth.dev/gobyexample/templates"
// import "git.sangeeth.dev/gobyexample/regex" // import "git.sangeeth.dev/gobyexample/regex"
import "git.sangeeth.dev/gobyexample/json" // import "git.sangeeth.dev/gobyexample/json"
import "git.sangeeth.dev/gobyexample/xml"
func main() { func main() {
// runes.Runes() // runes.Runes()
@ -55,5 +56,6 @@ func main() {
// formatting.Formatting() // formatting.Formatting()
// templates.Templates() // templates.Templates()
// regex.Regex() // regex.Regex()
json.Json() // json.Json()
xml.Xml()
} }

26
xml/xml.go Normal file
View File

@ -0,0 +1,26 @@
package xml
import (
"encoding/xml"
"fmt"
)
type Player struct {
XMLName xml.Name `xml:"player"`
Id int `xml:"id,attr"`
Name string `xml:"name"`
Weapons []string `xml:"weapons>weapon"`
}
func (p *Player) String() string {
return fmt.Sprintf("Player id=%v name=%s weapons=%v", p.Id, p.Name, p.Weapons)
}
func Xml() {
geralt := &Player{Id: 1, Name: "Geralt", Weapons: []string{"Silver Sword", "Steel Sword"}}
out, _ := xml.MarshalIndent(geralt, "", " ")
fmt.Println(string(out))
fmt.Println(xml.Header + string(out))
}