From the course: Learning the Go Standard Library

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Decoding XML

Decoding XML - Go Tutorial

From the course: Learning the Go Standard Library

Start my 1-month free trial

Decoding XML

- [Narrator] In a previous video, we looked at how to encode Go.Data into XML. So in this example, we're going to do the opposite and decode XML back into a Go structure. So let's open up our example file in the XML decode folder. So let's quickly examine our example before we begin. So this structure represents some data about a person, and in the main function down here, we have some XML code that we're going to decode into this struct. So let's start by uncommenting the XML. So the first thing to notice is that the root tag of the XML is different from the name of the struct. And the tag names in the XML are also different from the names of the struct fields. So we need to make a few changes to our code for this to work. So first let's declare a variable, and that's going to hold the instance of the structure. And then let's make some changes to the struct to map the tags to the fields. And we'll do this using the…

Contents