antchfx / xmlquery

xmlquery is Golang XPath package for XML query.

Home Page:https://github.com/antchfx/xpath

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

suggestion: include missing namespace in error message

torkelrogstad opened this issue · comments

In the parsing logic, xmlquery errors out if a namespace is missing:

xmlquery/parse.go

Lines 117 to 121 in 67c6eff

if tok.Name.Space != "" {
if _, found := p.space2prefix[tok.Name.Space]; !found && p.decoder.Strict {
return nil, errors.New("xmlquery: invalid XML document, namespace is missing")
}
}

The error message here is not very helpful. I'd suggest doing this instead:

			if space := tok.Name.Space; space != "" {
				if _, found := p.space2prefix[space]; !found && p.decoder.Strict {
					return nil, fmt.Errorf("xmlquery: invalid XML document, namespace %s is missing", space)
				}
			}