metaleap / go-xsd

[stable since 2013] a lib for loading XML Schema Definition (XSD) files ➜ plus, a tool `makepkg` to code-generate from any *.xsd your Go package with all needed `struct`s to readily `xml.Unmarshal()` documents into, based on the XSD's schema definitions. NOT REALLY MAINTAINED FOR YEARS NOW: try the forks if running into issues.
http://www.reddit.com/r/golang/comments/12g6sl/is_there_a_tool_that_generates_go_source_code_for/
MIT License
216 stars 66 forks source link

Strip unused attributes on Marshal #13

Closed Crell closed 7 years ago

Crell commented 9 years ago

I am not sure if this is an issue with this library or with the Marshal command. However, I am trying to generate (not read) an SVG file, using the generated SVG type definitions. The files are being generated, however, elements are including every single possible attribute that a given element could have, just with an empty string value.

While technically legal XML at that point and technically valid SVG, it's hugely wasteful (lots of unnecessary bytes to send in an HTTP request) and very difficult to read. Is there some way to cause empty attributes to simply be skipped? A given Walk command maybe, or some parameter to Marshal, or...?

Any tips welcome.

Crell commented 9 years ago

It looks like the way to do that would be to add "omitempty" to attribute field definitions: http://golang.org/pkg/encoding/xml/#Marshal