go-xmldom icon indicating copy to clipboard operation
go-xmldom copied to clipboard

How come this query does not return results?

Open beatscode opened this issue 7 years ago • 2 comments

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")
	}
}

image

beatscode avatar Mar 18 '18 14:03 beatscode

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?

beatscode avatar Mar 18 '18 14:03 beatscode

Seems to be a bug, that root node cannot be found using //... xpath.

subchen avatar Mar 19 '18 03:03 subchen