On Tue, 11 Oct 2016 10:12:50 -0700 (PDT) sm...@brillig.org wrote: [...] > >> > I'm trying to Marshal XML where an element has mixed content: > >> > https://www.w3.org/TR/REC-xml/#sec-mixed-content > >> > > >> > I tried just using []interface{} but if I put in just a string, > >> > Marshal surrounds each string with the name of the slice: [...] > >> Yes. "\nhello\n" and "\nworld\n" are what is called "character > >> data" in XML parlance. So if you go with the standard approach to > >> marshaling data to XML -- via a struct type with properly > >> annotated fields -- you should annotate the fields for your > >> character data chunks with the ",chardata" modifiers. [...] > > Sorry, I should have been more clear. The reason I used a slice > > was because I need an arbitrary number of elements. So I can't just > > use a static struct with the chardata tags. > > > I figured out a solution: > > https://play.golang.org/p/sWR1hAumYh > > I created a type that wraps string and implements the xml.Marshaler > interface. Then I just cast my strings to that type.
BTW you could just have your Elements field a literal as in your original example: <https://play.golang.org/p/6hQsPUycum> -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.