func findChild(x pathres.PathRes, p *pathexpr.PathExpr, ret *[]pathres.PathRes) { ch := x.GetChildren() for i := range ch { if ch[i].EvalPath(p) { *ret = append(*ret, ch[i]) } } }
//Print prints out the XPath result func Print(r pathres.PathRes) (string, error) { ret := bytes.NewBufferString("") e := xml.NewEncoder(ret) err := r.Print(e) if err != nil { return "", err } err = e.Flush() if err != nil { return "", err } return ret.String(), nil }
func findAncestor(x pathres.PathRes, p *pathexpr.PathExpr, ret *[]pathres.PathRes) { if x.GetParent().EvalPath(p) { *ret = append(*ret, x.GetParent()) } if x.GetParent() != x { findAncestor(x.GetParent(), p, ret) } }
func findPrecedingSibling(x pathres.PathRes, p *pathexpr.PathExpr, ret *[]pathres.PathRes) { if x == x.GetParent() { return } par := x.GetParent() ch := par.GetChildren() i := len(ch) - 1 for x != ch[i] { i-- } i-- for i >= 0 { findSelf(ch[i], p, ret) i-- } }
func findFollowingSibling(x pathres.PathRes, p *pathexpr.PathExpr, ret *[]pathres.PathRes) { if x == x.GetParent() { return } par := x.GetParent() ch := par.GetChildren() i := 0 for x != ch[i] { i++ } i++ for i < len(ch) { findSelf(ch[i], p, ret) i++ } }
func findSelf(x pathres.PathRes, p *pathexpr.PathExpr, ret *[]pathres.PathRes) { if x.EvalPath(p) { *ret = append(*ret, x) } }
func findParent(x pathres.PathRes, p *pathexpr.PathExpr, ret *[]pathres.PathRes) { if x.GetParent() != x && x.GetParent().EvalPath(p) { *ret = append(*ret, x.GetParent()) } }