XML Parsing - Handle Missing Attribute/Tag


I am just getting started with Go and for my first mini project trying to write a really simply snippet which will convert xml to csv.

I was able to get the snippet working pretty easily, but I am struggling to handle a simple edge case of missing tag. In the toy example seen on playground link below; when LastName is missing in the second section of XML, I want the snippet to update the slice with a blank string. As it stands now, in event of missing tag the snippet completely ignores the element, which then would cause issues when writing to csv.


Current Lastname Out:
[Raboy Doe]

Expected Lastname Out:
[Raboy “” Doe]


Change the model that you’re unmarshalling into: https://play.golang.org/p/16-J0L-eN-a

Thanks Sean - That’s done the trick.

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