Last active
August 29, 2015 14:11
-
-
Save kishorevaishnav/eae130fc4e45d80bfff9 to your computer and use it in GitHub Desktop.
Go - XML - Attributes & its value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also executed the same above code at http://play.golang.org/p/Ip-bcVkRYa