liveBook · Manning

Encoding/xml

As explained in Learn Go with Pocket-Sized Projects

encoding/xml is Go's standard-library package for encoding and decoding XML data.

encoding/xml decodes XML into Go structures and reads streaming responses through io.Reader values. Use xml.NewDecoder for an HTTP response body; use Unmarshal when the complete data is already a byte slice. section 6.5.4

Reading ECB exchange rates

Create an xml.Decoder from resp.Body, decode the ECB envelope, and calculate a requested exchange rate. Wrap malformed XML as an unexpected-format error and missing currencies as a lookup error.

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Explains Decoder selection, struct tags, nested paths, attributes, and error handling without descending into decoder internals.
Examples
Uses an ECB envelope containing nested Cube elements and currency and rate attributes.
What it assumes
Assumes Go structs, pointers, io.Reader values, HTTP responses, and basic error handling.
What you can do after
Apply it via Go's standard library to decode XML streams into tagged structures and process the resulting data.
How it connects
Connects XML decoding with JSON decoding, io.Reader, HTTP responses, Go structs, and error handling.

Also explained in

Compare how 2 books explain encoding/xml →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.