using XML files in Windows Phone 7 and XNA 4.0
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.
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
精彩评论