O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required