Skip to content

Instantly share code, notes, and snippets.

@softwarebygabe
Last active June 22, 2019 20:34
Show Gist options
  • Save softwarebygabe/45ec38e8e4a1a7ab04472558ce581267 to your computer and use it in GitHub Desktop.
Save softwarebygabe/45ec38e8e4a1a7ab04472558ce581267 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/xml"
"fmt"
)
type Cat struct {
XMLName xml.Name `xml:"cat"`
Name string `xml:"name,omitempty"`
Breed string `xml:"-"`
Age int `xml:"age,omitempty"`
}
func main() {
cat := Cat{
Name: "Olive",
Breed: "Oriental Shorthair",
Age: 0,
}
bytes, err := xml.MarshalIndent(cat, "", " ")
if err != nil {
panic(err)
}
fmt.Println(string(bytes))
}
@softwarebygabe
Copy link
Author

<cat>
  <name>Olive</name>
</cat>

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