Beispiel #1
0
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])
		}
	}
}
Beispiel #2
0
//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
}
Beispiel #3
0
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)
	}
}
Beispiel #4
0
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--
	}
}
Beispiel #5
0
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++
	}
}
Beispiel #6
0
func findSelf(x pathres.PathRes, p *pathexpr.PathExpr, ret *[]pathres.PathRes) {
	if x.EvalPath(p) {
		*ret = append(*ret, x)
	}
}
Beispiel #7
0
func findParent(x pathres.PathRes, p *pathexpr.PathExpr, ret *[]pathres.PathRes) {
	if x.GetParent() != x && x.GetParent().EvalPath(p) {
		*ret = append(*ret, x.GetParent())
	}
}