package main import ( "fmt" "log" "github.com/kr/pretty" ) var xmldoc = ` banaan ansjovis apenootjes ` func main() { doc, err := parse(xmldoc) if err != nil { log.Fatalln(err) } fmt.Println("\nGeparst XML-document:") pretty.Println(doc) fmt.Print(` Query: /animals/chimp[@naam="aap"]/food/text() `) /* SORT COLLECT 'child' 'type' 'text' text COLLECT 'child' 'name' 'node' food COLLECT 'child' 'name' 'node' chimp COLLECT 'child' 'name' 'node' animals ROOT PREDICATE EQUAL = COLLECT 'attributes' 'name' 'node' naam NODE ELEM Object is a string : aap COLLECT 'attributes' 'name' 'node' naam NODE */ result := doc.run(&xPath{ arg1: &dSort{ arg1: &dCollect{ ARG: collect__child__type__text__text, arg1: &dCollect{ ARG: collect__child__food, arg1: &dCollect{ ARG: collect__child__chimp, arg1: &dCollect{ ARG: collect__child__animals, arg1: &dRoot{}, }, arg2: &dPredicate{ arg1: &dEqual{ ARG: equal__is, arg1: &dCollect{ ARG: collect__attributes__name, arg1: &dNode{}, }, arg2: &dElem{ DATA: []interface{}{"aap"}, arg1: &dCollect{ ARG: collect__attributes__name, arg1: &dNode{}, }, }, }, }, }, }, }, }, }) fmt.Println("\nZoekresultaat:") pretty.Println(result) fmt.Println() }