Rolled back mistaken bugfix
This commit is contained in:
parent
3623786eeb
commit
4a541f77a5
14
node.go
14
node.go
|
@ -396,13 +396,15 @@ func (this *Node) SelectNodesRecursive(namespace, name string) []*Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
func rec_SelectNodes(cn *Node, namespace, name string, list *[]*Node, recurse bool) {
|
func rec_SelectNodes(cn *Node, namespace, name string, list *[]*Node, recurse bool) {
|
||||||
|
if (namespace == "*" || cn.Name.Space == namespace) && (name == "*" || cn.Name.Local == name) {
|
||||||
|
*list = append(*list, cn)
|
||||||
|
if !recurse {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, v := range cn.Children {
|
for _, v := range cn.Children {
|
||||||
if (namespace == "*" || v.Name.Space == namespace) && (name == "*" || v.Name.Local == name) {
|
rec_SelectNodes(v, namespace, name, list, recurse)
|
||||||
*list = append(*list, v)
|
|
||||||
}
|
|
||||||
if recurse {
|
|
||||||
rec_SelectNodes(v, namespace, name, list, recurse)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
xmlx_test.go
16
xmlx_test.go
|
@ -28,7 +28,8 @@ func TestWildcard(t *testing.T) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
list := doc.SelectNode("", "xml").SelectNodes("ns", "*")
|
list := doc.SelectNodes("ns", "*")
|
||||||
|
|
||||||
if len(list) != 1 {
|
if len(list) != 1 {
|
||||||
t.Errorf("Wrong number of child elements. Expected 1, got %d.", len(list))
|
t.Errorf("Wrong number of child elements. Expected 1, got %d.", len(list))
|
||||||
return
|
return
|
||||||
|
@ -93,24 +94,17 @@ func TestNodeSearch(t *testing.T) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes := doc.SelectNodesRecursive("", "item")
|
nodes := doc.SelectNodes("", "item")
|
||||||
if len(nodes) == 0 {
|
if len(nodes) == 0 {
|
||||||
t.Errorf("SelectNodes(): no nodes found.")
|
t.Errorf("SelectNodes(): no nodes found.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ch := doc.SelectNode("", "channel")
|
ch := doc.SelectNode("", "channel")
|
||||||
// Test that SelectNodes doesn't accidentally do recursive
|
// Test that SelectNodes properly selects multiple nodes
|
||||||
links := ch.SelectNodes("", "link")
|
links := ch.SelectNodes("", "link")
|
||||||
if len(links) != 1 {
|
|
||||||
t.Errorf("SelectNodes(): Expected 1, Got %d", len(links))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test SelectNodesRecursive does indeed get all of them
|
|
||||||
links = ch.SelectNodesRecursive("", "link")
|
|
||||||
if len(links) != 8 {
|
if len(links) != 8 {
|
||||||
t.Errorf("SelectNodesRecursive(): Expected 8, Got %d", len(links))
|
t.Errorf("SelectNodes(): Expected 8, Got %d", len(links))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue