ルート要素の名前空間接頭辞の定義を尊重していないXML構造です:XMLの整列化は、ここで
<root xmlns:test="http://test.com/testns">
<test:sub>
<title>this is title</title>
</test:sub>
</root>
これは、以下に定義する構造体とアンマーシャルます:
type Root struct {
XMLName xml.Name `xml:"root"`
Sub *Sub
}
type Sub struct {
XMLName xml.Name `xml:"http://test.com/testns sub"`
Title string `xml:"title"`
}
これが戻って整列化する内容です。
<root>
<sub xmlns="http://test.com/testns">
<title>this is title</title>
</sub>
</root>
marshalとsub elemeの後にルート名前空間接頭辞の定義が削除されます。 ntは接頭辞の代わりにURL名前空間を使用しています。ここにはcode
マーシャル/アンマーシャルはXML構造を変更しない方法はありますか?ありがとう!
xml名前空間が正しく動作しないようです。https://github.com/golang/go/issues/9519 https://github.com/golang/go/issues/11841 – RoninDev
もしそうなら、それはそれが受け入れられるように、おそらく最も良い答えに作られています。 – ijt