Working with XML
This section briefly describes how to work with XML data in Go using records. The idea behind XML and Go is the same as with JSON and Go. You put tags in Go structures in order to specify the XML tags and you can still serialize and deserialize XML records using xml.Unmarshal()
and xml.Marshal()
, which are found in the encoding/xml
package. However, there exist some differences that are illustrated in xml.go
:
package main
import (
"encoding/xml"
"fmt"
)
type Employee struct {
XMLName xml.Name `xml:"employee"`
ID int `xml:"id,attr"`
FirstName string `xml:"name>first"`
LastName string `xml:"name>last"`
Height float32 `xml:"height,omitempty"`
Address
Comment string `xml:",comment"`
}
This is where the structure for the XML data is defined. However, there is additional information regarding the name and the type of each...