Skip to content

Instantly share code, notes, and snippets.

@kishorevaishnav
Last active August 29, 2015 14:11
Show Gist options
  • Save kishorevaishnav/eae130fc4e45d80bfff9 to your computer and use it in GitHub Desktop.
Save kishorevaishnav/eae130fc4e45d80bfff9 to your computer and use it in GitHub Desktop.
Go - XML - Attributes & its value
package main
import (
"encoding/xml"
"fmt"
)
type Embed struct {
XMLName xml.Name `xml:"Embed"`
Body string `xml:"Body,omitempty"`
Id XMLId `xml:"Id,omitempty"`
}
type XMLId struct {
XMLName xml.Name `xml:"Id"`
Value string `xml:",chardata"`
Type string `xml:"type,attr"`
}
func main() {
fmt.Println("Hello, playground")
em := Embed{}
em.Body = "222"
em.Id.Value = "5"
em.Id.Type = "integer"
x, _ := xml.MarshalIndent(em, "", " ")
fmt.Println(string(x))
}
@kishorevaishnav
Copy link
Author

Also executed the same above code at http://play.golang.org/p/Ip-bcVkRYa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment