encoding/xml is Go’s standard-library package for converting XML documents and Go values. Define structs with XML tags, then use Marshal or Unmarshal to serialize or parse data. Its tag syntax also maps attributes, namespaces, comments, and structured elements. section 10.5.2 section 10.11
A configuration model shared by JSON and XML
A Config struct can map Name and Version to XML attributes, Namespace to an optional namespace attribute, Debug and Port to elements, and Comment to an XML comment. Adding JSON tags to the same fields lets one Go type support both representations. section 10.5.2
.Defining a configuration structure with XML tags
[source,go,linenums]
----
type Config struct {
XMLName xml.Name `xml:"configuration"` // Root element name
Name string `json:"name" xml:"name,attr"` // XML attribute
Version string `json:"version" xml:"version,attr"` // XML attribute
Namespace string `xml:"xmlns,attr,omitempty"` // XML namespace
Debug bool `json:"debug" xml:"debug"`
Port int `json:"port" xml:"port"`
Host string `json:"host" xml:"host,omitempty"`
Comment string `xml:",comment"` // XML comment
}
----
Inspect the complete Config definition and its XML field tags. section 10.5.2
A conversion pipeline parses input into an intermediate Go struct, then marshals that validated and normalized representation into the requested format. This composes with file, network, and in-memory I/O in a larger CLI tool. section 10.5.2 section 10.10

