Simple Deserialization with XML and XNA Content Pipeline

The XNA Content Pipeline can at first seem daunting but is extremely easy to use once you get the hang of it. I wanted to share a small class that I created to represent an enemy entity that has its information stored in an XML format. The content pipeline reads my XML animated sprite data and imports/processes it to a .xnb file at build time. At run time, this .xnb file is then deserialized into an object that I can use to draw to the screen.

My XML content looks like this:

The C# class associated with this data at run time looks like this:

The XNA Content Pipeline has a built in importer and processor for XML –> Object deserialization. As long as you have the “Type” attribute of the “Asset” element set to the correct namespace and class, the Content Pipeline will take care of the rest. Just load this content like so:

Reference: http://msdn.microsoft.com/en-us/library/ff604979

One thought on “Simple Deserialization with XML and XNA Content Pipeline

Leave a Reply

Your email address will not be published. Required fields are marked *