0PricingLogin
Go Academy · Lesson

encoding/xml

Work with XML.

Working with XML

XML is a verbose, tag-based format still common in legacy systems and configs. Go's encoding/xml package marshals and unmarshals it, mirroring the json package.

Marshal to XML

xml.Marshal turns a Go value into XML bytes.

package main

import (
	"encoding/xml"
	"fmt"
)

type User struct {
	Name string
	Age  int
}

func main() {
	b, _ := xml.Marshal(User{"Ann", 30})
	fmt.Println(string(b))
}

All lessons in this course

  1. encoding/json Recap
  2. encoding/xml
  3. encoding/csv
  4. gob and Binary Encoding
← Back to Go Academy