Search
Write a publication
Pull to refresh
170.87

Go *

Compiled, multithreaded programming language

Show first
Period
Level of difficulty

XML parsing into plain Map in Golang

Level of difficultyEasy
Reading time4 min
Views4.1K

While in 2024 using XML looks a bit outdated, it still happens. And sometimes it happens we are to deal with XML having "free-structure", i.e. it couldn't be parsed into tree of user-defined structs. For JSON there still is a way to parse it with a single call into map[string]any and work with it using careful type assertions. Regretfully, there is no similar feature for XML (in Golang). Here I'll draft suitable function and demonstrate it - both for others and for myself if I ever need this again (recreating it from scratch may be somewhat painful).

Let's see implementation

Authors' contribution