从结构编码xml

I'm new to go and trying to get the following piece of code to work with no luck. Looks like I don't have the struct of structs part correctly coded. Help!

package main

import (
    "encoding/xml"
    "fmt"
    "os"
)

func main() {

    type Person struct {
        Email string `xml:"email"`
        Phone string `xml:"phone"`
    }

    type Host struct {
        Hostname string `xml:"hostname"`
        Address  string `xml:"address"`
    }

    type Asset struct {
        person Person
        host   Host
    }

    p := &Person{Email: "person@a.com", Phone: "1111"}
    h := &Host{Hostname: "boxen", Address: "1 Place St"}
    a := &Asset{person: *p, host: *h}

    enc := xml.NewEncoder(os.Stdout)
    enc.Indent(" ", " ")
    if err := enc.Encode(p); err != nil {
        fmt.Printf("error: %v
", err)
    }
    if err := enc.Encode(h); err != nil {
        fmt.Printf("error: %v
", err)
    }
    if err := enc.Encode(a); err != nil {
        fmt.Printf("error: %v
", err)
    }
}

Go playground here

Expected output. What I currently get is an empty Asset element.

 <Asset>
   <Person>
    <email>person@a.com</email>
    <phone>1111</phone>
   </Person>
   <Host>
    <hostname>boxen</hostname>
    <address>1 Place St</address>
   </Host>
 </Asset>

You must export the properties of the "Asset" type by making their names start with a capital letter:

type Asset struct {
  Person Person
  Host   Host
}

As long as person and host are unexported, there is no way for enc.Encode to know about them. Exporting them will give your desired output.

package main

import (
    "encoding/xml"
    "fmt"
    "os"
)

func main() {

    type Person struct {
        Email string `xml:"email"`
        Phone string `xml:"phone"`
    }

    type Host struct {
        Hostname string `xml:"hostname"`
        Address  string `xml:"address"`
    }

    type Asset struct {
        Person Person
        Host   Host
    }

    p := &Person{Email: "person@a.com", Phone: "1111"}
    h := &Host{Hostname: "boxen", Address: "1 Place St"}
    a := &Asset{Person: *p, Host: *h}

    enc := xml.NewEncoder(os.Stdout)
    enc.Indent(" ", " ")

    if err := enc.Encode(a); err != nil {
        fmt.Printf("error: %v
", err)
    }
}