diff --git a/xpath_function_test.go b/xpath_function_test.go index 9feff05..889b6dd 100644 --- a/xpath_function_test.go +++ b/xpath_function_test.go @@ -115,7 +115,7 @@ func Test_func_string_length(t *testing.T) { func Test_func_substring(t *testing.T) { test_xpath_eval(t, empty_example, `substring("motor car", 6)`, " car") test_xpath_eval(t, empty_example, `substring("metadata", 4, 3)`, "ada") - //test_xpath_eval(t, empty_example, `substring("12345", 5, -3)`, "") ?? it should be 1 ?? + //test_xpath_eval(t, empty_example, `substring("12345", 5, -3)`, "") // ?? it should be 1 ?? //test_xpath_eval(t, empty_example, `substring("12345", 1.5, 2.6)`, "234") //test_xpath_eval(t, empty_example, `substring("12345", 0, 3)`, "12") // panic?? //test_xpath_eval(t, empty_example, `substring("12345", 5, -3)`, "1") @@ -212,8 +212,8 @@ func Test_func_round(t *testing.T) { } func Test_func_namespace_uri(t *testing.T) { - //test_xpath_eval(t, mybook_example, `namespace-uri(//mybook:book)`, "http://www.contoso.com/books") - //test_xpath_elements(t, mybook_example, `//*[namespace-uri()='http://www.contoso.com/books']`, 3, 9) + test_xpath_eval(t, mybook_example, `namespace-uri(//mybook:book)`, "http://www.contoso.com/books") + test_xpath_elements(t, mybook_example, `//*[namespace-uri()='http://www.contoso.com/books']`, 3, 9) } func Test_func_normalize_space(t *testing.T) { diff --git a/xpath_test.go b/xpath_test.go index a017a8f..f89fa42 100644 --- a/xpath_test.go +++ b/xpath_test.go @@ -285,10 +285,12 @@ type Attribute struct { type TNode struct { Parent, FirstChild, LastChild, PrevSibling, NextSibling *TNode - Type NodeType - Data string - Attr []Attribute - lines int + Type NodeType + Data string + Attr []Attribute + NamespaceURL string + Prefix string + lines int } func (n *TNode) Value() string { @@ -346,7 +348,7 @@ func (n *TNodeNavigator) Prefix() string { if n.attr == -1 && strings.Contains(n.curr.Data, ":") { return strings.Split(n.curr.Data, ":")[0] } - return "" + return n.curr.Prefix } func (n *TNodeNavigator) NamespaceURL() string { @@ -357,7 +359,7 @@ func (n *TNodeNavigator) NamespaceURL() string { } } } - return "" + return n.curr.NamespaceURL } func (n *TNodeNavigator) Value() string { @@ -842,11 +844,16 @@ func createMyBookExample() *TNode { */ - lines := 0 + var ( + prefix string = "mybook" + namespaceURL string = "http://www.contoso.com/books" + ) + lines := 1 doc := createNode("", RootNode) + doc.lines = lines lines++ books := doc.createChildNode("books", ElementNode) - books.addAttribute("xmlns:mybook", "http://www.contoso.com/books") + books.addAttribute("xmlns:mybook", namespaceURL) books.lines = lines lines++ data := []struct { @@ -861,8 +868,10 @@ func createMyBookExample() *TNode { } for i := 0; i < len(data); i++ { v := data[i] - book := books.createChildNode("mybook:book", ElementNode) + book := books.createChildNode("book", ElementNode) book.addAttribute("id", v.id) + book.Prefix = prefix + book.NamespaceURL = namespaceURL book.lines = lines lines++ title := book.createChildNode("title", ElementNode)