credit unsplash.com Shahadat Rahman @hishahadat

Parsing XML with Golang

Unmarshal XML with golang

Ivan S Kirkpatrick
Published in
6 min readMar 20, 2020

--

Learning to Unmarshal XML with golang was not something I have done before. Unmarshalling JSon is a more common tasking as XML seems to have lost some of its luster of late if it ever really had any. I was never a fan of XML so when most of the new work seemed to shift toward Json I was pretty much all for it.

Florida Lottery

In my latest project, I have a task to retrieve the Florida Lottery Winning Numbers. I used to work there a few years back as a Java Contractor so I am somewhat familiar with how their website and data presentation works. The actual games are a completely different operation. The website offers data and game information in a colorful and fairly respectable UI. I would have preferred the Lottery offered an API to access the data I needed but I was pretty sure they never got around to it and did not look very hard to see if it was available.

The Issue

The issue I had to deal with that took up so much time was acknowledging that I had to create the proper golang structs to contain the Lottery XML elements. Originally I had hoped to be able to just scan the XML, pick out the item tags and collect those into an array for subsequent processing. After an unsuccessful try of that, I had to reconcile myself to creating the full…

--

--

Ivan S Kirkpatrick

Engineer and veteran, 13 years of Design Engineering, 20+ years in Software Engineering, Go enthusiast. I read a lot, write some too, ivank2139@tessaract.net