You can modify how a struct is serialized to XML by annotating fields with tags.
By providing XMLName
, this will be serialized as <data>...</data>
and not <ShowXMLName>..</ShowXMLName>
.
https://codeeval.dev/gist/39b623f6b95471c73801c86aa685d492
Fields marked with xml:"-"
are not serialized.
https://codeeval.dev/gist/90991bb26633a0c7ba0d019ec6731b93
To skip serializing fields with empty values, use xml:",omitempty"
.
https://codeeval.dev/gist/94ec1eddc98aae3f5fccbb936698f564
To change serialization from XML element to XML attribute use xml:",attr"
.
https://codeeval.dev/gist/6016e3aa0437d587dd6ab22c1a0c34e9
To change serialization from XML element to character data use xml:",chardata"
.
https://codeeval.dev/gist/c4db0a15425fd4a152ff797b1629d0e0
To change serialization from XML element to CDATA use xml:",cdata"
.
https://codeeval.dev/gist/a53ec6509d2fd5299494f502b947460f
To serialize the value verbatim, use xml:",innerxml"
.
https://codeeval.dev/gist/b4744b38f33aaaf34353f939d24f0158
To serialize field as XML comment, use xml:",comment"
. Value can’t contain --
.
https://codeeval.dev/gist/bec8fbc86fa88d22a2da4db0acc6c463
xml:"a>b>str"
nests XML element. This also influences parsing.