XML Marshal & Unmarshal (namespace attribute issue)

xuanbao · · 650 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Okay guys, </p> <p>Maybe somebody could give some insight here... I seem to be hitting a brick wall with the encoding/XML library.</p> <p>For the life of me, I can&#39;t replicate the valid XML attributes from &lt;gpx&gt;</p> <p>Basically i&#39;m unmarshalling the XML data from a GPS file, then marshalling it back into another file. Everything is working correctly, except the attribute tags for the root XML &lt;gpx&gt;.</p> <p>I&#39;ve tried various func (c *gpx) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {} type approaches to no avail. Basically I just want the root tag &lt;GPX&gt; to have all the attributes assigned correctly. Why you can&#39;t do </p> <p>Attributes []xml.Attr <code>xml:&#34;,attr&#34;</code>or something similar is beyond me. </p> <p>Current issue tracker: <a href="https://github.com/golang/go/issues/3633" rel="nofollow">https://github.com/golang/go/issues/3633</a></p> <p>Sample struct with code -&gt; <a href="http://pastebin.com/gK0feeWH" rel="nofollow">http://pastebin.com/gK0feeWH</a> Good XML header -&gt; <a href="http://pastebin.com/XjEZuBa1" rel="nofollow">http://pastebin.com/XjEZuBa1</a> Bad XML header -&gt; <a href="http://pastebin.com/LnTckfAW" rel="nofollow">http://pastebin.com/LnTckfAW</a></p> <p>Any help would be greatly appreciated, </p> <p>Thank you.</p> <hr/>**评论:**<br/><br/>Xonzo: <pre><p>I have an example in the Go playground if it helps...</p> <p><a href="http://play.golang.org/p/J7wy6306Cj" rel="nofollow">http://play.golang.org/p/J7wy6306Cj</a></p> <p>My program will replicate the GPS file exactly <strong>EXCEPT</strong> for the &lt;gpx attribute&gt; portion. If I replace the &lt;GPX&gt; tag at the top I can import my file into Garmin Basecamp with no issues. </p> <p>Sadly other encoding libraries from other languages work correctly, but I would prefer to use Go.... <em>sigh</em></p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

650 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传