golang/go

encoding/xml: Unmarshal does not properly handle NCName in XML namespaces

fantasist opened this issue · 8 comments

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 "

This issue seems to be a duplicate of #6800

Dup of #6800.

rsc commented

See #11841.

CL https://golang.org/cl/12570 mentions this issue.

rsc commented

Blocked on #13400.

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.

@fantasist

Here's an unmarshal wrapper that allows namespace prefix

https://play.golang.org/p/zLixkblqVOB

The provided case written as a test passes with the suggested CL of #9519 .