Xml: unmarshalling optional subelements

what am I doing wrong here? https://play.golang.org/p/84fEBDSHmJ

I cannot unmarshall the subelement “I” from the element "Value."
The optional elements I, B, U are used to store formatted text (italic, bold, underlined). If the text is unformatted, I am able to unmarshall the Value element using a tag of “, chardata.” But do not know why I cannot unmarshall the subelements I, B, U when they are there.


I think the issue is that you’re using > before the character in the XML struct tags for the I,B,U fields. Since Value tag matches the Value struct in depth the extra > are not needed for children.


Thanks Jason,
My troubles go deeper thought. Turned out, the children elements can be arbitrarily nested, eg a word can be both bold and underlined in the middle of an italicized sentence. I ended using innerxml tag and then sanitizing the content.


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.