encoding/xml: Unmarshal does not properly handle NCName in XML namespaces
fantasist opened this issue · 8 comments
fantasist commented
Example:
type A struct {
XMLName xml.Name xml:"a:B"
}
Struct A is marshaled to "<a:B></a:B>", as expected.
However if we run
a := A{}
xml.Unmarshal([]byte("<a:B></a:B>"), &a)
It results in an error saying "unexpected error: expected element type <a:B> but have "
gopherbot commented
CL https://golang.org/cl/12570 mentions this issue.
iwdgo commented
The provided example is invalid XML as the prefix a
for element <a:B>
is not bound. The prefix needs a declaration like xmlns:a="...". The reported error : expected element type <a:B> but have <B>
points to the correct element.
Demitroi commented
Here's an unmarshal wrapper that allows namespace prefix
iwdgo commented
The provided case written as a test passes with the suggested CL of #9519 .