Teaching a man to fish
Variants of the following question come up somewhat regularly on the XNA forums:
- I want to import game data from an XML file
- I plan to do this using the Content Pipeline IntermediateSerializer
- I have my custom data type all ready to go
- But I don't know how I should format the XML for it!
You already have the tools to answer this yourself. Here's how:
Fire up Visual Studio and create a new Console Application project.
Right-click on the References node, and add the Microsoft.Xna.Framework.Content.Pipeline assembly.
Add using declarations for the System.Xml and Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate namespaces.
Add a test class with the same layout as whatever data you want to serialize, but initialized with dummy test values. For instance:
Add this code to Main:
Run the program. Look in the bin\Debug folder, and open the test.xml output file. With the class shown above, this will look like:
Tada! That's how IntermediateSerializer represents this particular class in XML.