golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.21k stars 17.46k forks source link

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

Open fantasist opened 9 years ago

fantasist commented 9 years ago

Example: type A struct { XMLName xml.Name xml:"a:B" } Struct A is marshaled to "</a:B>", as expected. However if we run a := A{} xml.Unmarshal([]byte("</a:B>"), &a)

It results in an error saying "unexpected error: expected element type but have "

c4milo commented 9 years ago

This issue seems to be a duplicate of https://github.com/golang/go/issues/6800

mikioh commented 9 years ago

Dup of #6800.

rsc commented 9 years ago

See #11841.

gopherbot commented 9 years ago

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

rsc commented 8 years ago

Blocked on #13400.

iwdgo commented 6 years ago

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 4 years ago

@fantasist

Here's an unmarshal wrapper that allows namespace prefix

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

iwdgo commented 1 month ago

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