With the NewDecoder function of the xml package, the Decoder for the XML content is created.
By calling the Token method on the Decoder, the xml.Token is received. The xml.Token is the interface which holds the token type. The behavior of the code can be defined, based on the type. The sample code tests if the parsed xml.StartElement is one of the book elements. Then it partially parses the data into a Book structure. This way, the position of the pointer in the underlying Reader in the Decoder is shifted by the struct data, and the parsing can continue.