package main import ( "encoding/xml" ) type docType struct { animals *animalsType } type animalsType struct { XMLName xml.Name `xml:"animals"` Chimp []*animalType `xml:"chimp"` Cat []*animalType `xml:"cat"` } type animalType struct { Name string `xml:"name,attr"` Food foodType `xml:"food"` } type foodType struct { Text string `xml:",chardata"` } func parse(xmldoc string) (*docType, error) { var animals animalsType err := xml.Unmarshal([]byte(xmldoc), &animals) return &docType{ animals: &animals, }, err } func (doc *docType) run(xpath *xPath) []interface{} { return xpath.do(doc) }