Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go XML marshalling without encoding HTML entities

Tags:

xml

go

I'd like to marshal a struct into XML, but without encoding special HTML-entities. See this example:

http://play.golang.org/p/7NOhOTwlHr

The string test&abc gets converted to test&abc, but I'd like it to stay test&abc

like image 641
chrikoch Avatar asked May 20 '26 02:05

chrikoch


2 Answers

You can use the tag ",innerxml" as show in the example. Here it explains that ",innerxml" makes unmarshal "assign raw XML data to it". But it also work well with Marshal avoiding the string formating.

http://play.golang.org/p/z8JQjRdbV4

like image 118
joaonrb Avatar answered May 21 '26 18:05

joaonrb


The ampersand is escaped using the rules in the XML specification. It is not possible to disable escaping in the output of the standard encoding/xml package.

(Ampersand escaping in HTML and XML shares a common heritage from SGML, but each is specified separately. One does not derive from or reference the other).

like image 26
Simon Fox Avatar answered May 21 '26 17:05

Simon Fox



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!