How to unmarshal XML attributes with colons?

前端 未结 1 394
半阙折子戏
半阙折子戏 2021-02-04 11:36

Some SVG/XML files I\'m working with have dashes and colons in attribute names - for example:


  

        
相关标签:
1条回答
  • 2021-02-04 11:47

    Your example fragment is not quite correct, since it does not include an XML namespace binding for the xlink: prefix. What you probably want is:

    <g xmlns:xlink="http://www.w3.org/1999/xlink">
      <a xlink:href="http://example.com" data-bind="121">lala</a>
    </g>
    

    You can unmarshal this attribute using the namespace URL:

    XlinkHref string `xml:"http://www.w3.org/1999/xlink href,attr"`
    

    Here is an updated copy of your example program with the namespace fix.

    0 讨论(0)
提交回复
热议问题