Example #1
0
func first(node *xmlpath.Node, xpath string) (content string, err error) {
	path, err := xmlpath.CompileWithNamespace(xpath, soap.GetAllNamespaces())
	if err != nil {
		return
	}
	content, _ = path.String(node)
	return
}
Example #2
0
func any(node *xmlpath.Node, xpath string) (found bool, err error) {
	path, err := xmlpath.CompileWithNamespace(xpath, soap.GetAllNamespaces())
	if err != nil {
		return
	}

	found = path.Exists(node)
	return
}
Example #3
0
func xpath(node *xmlpath.Node, xpath string) (nodes []xmlpath.Node, err error) {
	path, err := xmlpath.CompileWithNamespace(xpath, soap.GetAllNamespaces())
	if err != nil {
		return
	}

	nodes = make([]xmlpath.Node, 0, 1)
	iter := path.Iter(node)
	for iter.Next() {
		nodes = append(nodes, *(iter.Node()))
	}
	return
}
Example #4
0
func assertXPath(c *C, node *dom.Document, request string, expected string) {
	content := strings.NewReader(node.String())

	path, err := xmlpath.CompileWithNamespace(request, soap.GetAllNamespaces())
	if err != nil {
		c.Fatalf("Xpath %s gives error %s", request, err)
	}
	var root *xmlpath.Node
	root, err = xmlpath.Parse(content)
	if err != nil {
		c.Fatalf("Xpath %s gives error %s", request, err)
	}

	var e string
	var ok bool
	e, ok = path.String(root)
	c.Assert(ok, Equals, true)
	c.Assert(e, Equals, expected)
}