Maps, Levels and parsing XML

I made a little game in ActionScript and Flashpunk, the engine parsed a lot of xml on its own so coming to monogame I realise I need to do a lot more myself which I am happy to do.

However right now, I have tried just simply having xml levels in my content pipeline and if set to build I always get a failed error but nothing meaningful to help. Do XML files have to follow a certain standard to build with content pipeline?

A very simple XML level exported by a tool (OGMO) I use looks like this:

<level width="48" height="48">
  <grass tileset="base" exportMode="TrimmedCSV">3,3,3</grass>
  <base tileset="base" exportMode="TrimmedCSV">15,11,11</base>
</level>

I can use C# to parse it all to a string and work with it that way, also I can (almost) serialize it to an object as well. However I want to build it into the project so the released files are not just XML that anyone can edit.

Hm, I’m not sure how you have your content build pipeline setup exactly, but you can definitely create content pipeline processors and importers for XML.

For instance, this code demonstrates how to load in an XML file that is exported from the Tiled level editor. You could probably copy and paste a lot of that into a new content importer and processor.

If you want documentation on how to roll your own, then I can provide you with that.

PS: I would appreciate it if you included your build log.

Thanks for the quick reply!

I am not home so have not posted a great amount of detail. Everything is just setup as a basic windows project, so default build settings I assume.

If that tile editor works nicely with some provided code to use XML files I might learn my way around that.

I will post my build log later then and try figure out why the XML files are not building at all.

Is my understanding correct that if you don’t build and only choose to copy/include, then if you ship the game levels will be easily accessed by players in the game directory? Otherwise if you build the XML files, they are turned into library files as such?

I have a game that loads from xml… I did this exactly to provide the flexibility of 3rd party editing of the game. (Content can be added without modifying the code) So if you still have issues when you’ve done the above, respond here, and I’ll load my project and spoon-feed you all the settings. :slight_smile:

Thanks monopalle,

I will probably pick up a bit more at the end of this week when I have free time and try some XML loading again, would love some help then I think.

Seen your other replies to my posts around as well, appreciate the help!

You have three options:

  1. roll your own loading code using XmlReader etc. See msdn for docs. Probably the most work but it’s the most flexible if you’re not defining the format of the xml yourself. In this case you should be setting your xml content to Copy to Output so the content piped need does not process it.

  2. Use .net’s XmlSerializer. This is a wonderful solution providing the xml conforms to the necessary format. It’s fairly configurable, again see msdn and use Copy to Output.

  3. Use Xna’s IntermediateSerializer. This is the format that the content pipeline natively understands. It is in my opinion the best option, but does have some quirks. You can set up your xml, feed into the pipeline and load your deserialized instances using Content.Load(). See these posts by Teh Shawn for best info:
    http://www.shawnhargreaves.com/blogindex.html#intermediateserializer