// Note: this illustrates ValuesForKey() and ValuesForPath() methods package main import ( "fmt" "github.com/clbanning/mxj" "log" ) var xmldata = []byte(` William H. Gaddis The Recognitions One of the great seminal American novels of the 20th century. Austin Tappan Wright Islandia An example of earlier 20th century American utopian fiction. John Hawkes The Beetle Leg A lyrical novel about the construction of Ft. Peck Dam in Montana. T.E. Porter King's Day A magical novella. `) func main() { fmt.Println(string(xmldata)) m, err := mxj.NewMapXml(xmldata) if err != nil { log.Fatal("err:", err.Error()) } v, _ := m.ValuesForKey("books") fmt.Println("path: books; len(v):", len(v)) fmt.Printf("\t%+v\n", v) v, _ = m.ValuesForPath("books.book") fmt.Println("path: books.book; len(v):", len(v)) for _, vv := range v { fmt.Printf("\t%+v\n", vv) } v, _ = m.ValuesForPath("books.*") fmt.Println("path: books.*; len(v):", len(v)) for _, vv := range v { fmt.Printf("\t%+v\n", vv) } v, _ = m.ValuesForPath("books.*.title") fmt.Println("path: books.*.title len(v):", len(v)) for _, vv := range v { fmt.Printf("\t%+v\n", vv) } v, _ = m.ValuesForPath("books.*.*") fmt.Println("path: books.*.*; len(v):", len(v)) for _, vv := range v { fmt.Printf("\t%+v\n", vv) } }