我正在使用的一些 SVG/XML 文件在屬性名稱中有破折號和冒號 - 例如:<g>
<a xlink:href="http://example.com" data-bind="121">...</a>
</g>我試圖弄清楚如何使用golang'sencoding/xml包解組這些屬性。雖然虛線屬性有效,但帶有冒號的屬性無效:package mainimport ( "encoding/xml" "fmt")var data = `<g> <a xlink:href="http://example.com" data-bind="121">lala</a></g>`type Anchor struct { DataBind int `xml:"data-bind,attr"` // this works XlinkHref string `xml:"xlink:href,attr"` // this fails}type Group struct { A Anchor `xml:"a"`}func main() { group := Group{} _ = xml.Unmarshal([]byte(data), &group) fmt.Printf("%#v\n", group.A)}這些看似合法的屬性名稱;知道如何提取xlink:href一個嗎?謝謝。
- 1 回答
- 0 關注
- 237 瀏覽
添加回答
舉報
0/150
提交
取消