Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@kishorevaishnav kishorevaishnav commented Dec 14, 2014

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