Rust, Software Development

Rust – Read EPCIS 1.2 XML Into Struct Instance

This post is about reading an EPCIS 1.2 XML into a Struct instance. EPCIS stands for Electronic Product Code Information Services. It is a global GS1 Standard for creating and sharing visibility event data in certain industries, both within and across enterprises, to enable users to gain a shared view of physical or digital objects within a relevant business context. This enables systems from different organizations to speak to each other in certain vocabulary known to all of them.

For writing EPCIS 1.2 XML to files, please read Generate EPCIS 1.2 XML.


We have the following items used for this post.


For our input file, we’ll use an existing file to read from. It is an EPCIS 1.2 as defined in the second line where schemaVersion is set to “1.2”. It also has 2 major elements – EPCISHeader and EPCISBody.

EPCIS Structs

The structs for our codes represent some elements in the XML document. This is to easily read EPCIS XML into a struct instance. Most of them have the same name as the XML element they represent. Some structs contain other structs as some XML elements contain other elements.

The Codes

All the aforementioned structs should appear before the main function. The codes below read the XML file using BufRead for performance reasons. They also pass the reader object to the from_reader function to perform the actual deserialization.

The codes also use the Debug trait to display the content of a struct using println!


As shown below, the codes read the EPCIS XML into the struct instance of EPCISDocument.

The complete console output is available as output.txt.



Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.

You Might Also Like