go-xmldom
go-xmldom copied to clipboard
How come this query does not return results?
I'm trying to search for a node in a document I think my xpath query is correct in syntax but does not return any elements. The following test fails.
func TestLayerIDFinding(t *testing.T) {
xm :=
`<?xml version="1.0" encoding="UTF-8"?><_signin.SignInButton X="28" Y="352" Width="320" Height="50" LayerID="7FD41E11-85C2-45CC-AFFA-E9D480F22503" />`
node := xmldom.Must(xmldom.ParseXML(xm))
xpath := `//_signin.SignInButton[@LayerID="7FD41E11-85C2-45CC-AFFA-E9D480F22503"]`
r := node.Root.QueryOne(xpath)
if r == nil {
t.Error("Could Not find element")
} else {
t.Log("Element found")
}
}

I was able to get this to work by changing LayerID to id and using FindByID. Curious if I should stay away from xpath queries like this?
Seems to be a bug, that root node cannot be found using //... xpath.