Right-click on the file in the Pipeline tool and select Open with
. This will allow you to select the tool used to edit the XML file.
Looking at your sample project, I can see a few things immediately.
- You have a .cs file in the Content directory and added to the mgcb file. I don’t know what this was trying to achieve.
- XML files to be compiled with the content pipeline need to start with XnaContent and Asset nodes, as in the template XML file if you select
New Item
in the Pipeline tool and select XML Content
.
This is a sample XML asset that would contain a Dictionary<Int, String>
.
<?xml version="1.0" encoding="utf-8" ?>
<XnaContent>
<!-- TODO: replace this Asset with your own XML asset data. -->
<Asset Type="System.Collections.Generic.Dictionary[System.Int32, System.String]">
<!-- Your asset fields go here -->
</Asset>
</XnaContent>
This will work without any additional code because all of the types Dictionary
, Int32
and String
are known to the content pipeline through mscorlib. If you want to use your own types, such as an array of Tile
, you will need to have the Tile
class in its own class library so it can be accessed by the content pipeline and the game. The compiled class library assembly then needs to be added to the MGCB project as a reference. Select the root node in the treeview in the Pipeline tool and double-click on References in the Properties window.
Now that you have the class library containing the Tile
type available to the content pipeline, you need to construct your XML file in a way that the content pipeline can understand.
<?xml version="1.0" encoding="utf-8" ?>
<XnaContent>
<Asset Type="System.Collections.Generic.List[GB_Zelda.Map.Tile]">
<Item>
<XPos>1</XPos>
<YPos>1</YPos>
<ZPos>1</ZPos>
<TextureXPos>0</TextureXPos>
<TextureYPos>0</TextureYPos>
<TextureName>Overworld_Tiles</TextureName>
</Item>
</Asset>
</XnaContent>
This should build into a XNB file. To load this through the ContentManager, use the following
var tiles = Content.Load<List<Tile>>("Xml/Maps/Test_Map");
I have edited your project to show this working, available here. Note that I removed the source control bindings in the solution and project because VS’s source control bindings are annoying when you don’t have access to the source control server they’re bound to.