Search⌘ K

The XML Data Format

Explore how to work with XML data in Go by learning to marshal and unmarshal XML to structs, parse XML tokens, and handle XML streams using the encoding/xml package. This lesson helps you understand XML data manipulation in Go for effective data serialization and deserialization.

What is XML? #

XML is a markup language that sets some rules to encode data in both human and machine-readable format. It stands for eXtensible Markup Language. The XML equivalent for the JSON example used in the last lesson is:

<Person>
<FirstName>Laura</FirstName>
<LastName>Lynn</LastName>
</Person>
svg viewer

Marshalling and unmarshaling

Like the json package xml contains a Marshal() and an UnMarshal() function to encode and decode data to and from XML. In the same way as with JSON, XML-data can be marshaled or un-marshaled to/from structs.

Here is an example where we see this in ...