Question

I'm working on a basic tiling engine for XNA 4.0 on Windows Phone 7. I have a bunch of mapdata xml files with all the tile positions, powerup positions etc.

I was wondering what the best way of using these? I've read that if I want to use them with the Content then I have to alter the layout of the xml files.

Is there any way to load these files on to the device within the project and read the data from them?

Many thanks, ant.

Was it helpful?

Solution

The way I did it was make the XML file an embedded resource, not content, then I could access them in code:

Assembly app = Assembly.GetExecutingAssembly();
        XmlSerializer ser = new XmlSerializer(typeof(xmlType));
        string[] resources = app.GetManifestResourceNames();

        foreach (string resourceName in resources)
        {                                 
         xmlObject = (xmlType)ser.Deserialize(new StreamReader(app.GetManifestResourceStream(resourceName)));                    
        }

xmlType is a class that represents my XML Format

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top