jwraith

Okay, so a simple query. How to I use an XML file when when developing for the 360.

I can do it fine in windows, but as of yet I am completly lost on how to load the file when on the 360.


Re: XNA Framework XML usage on 360

Jim Perry

Have you tried it on the 360




Re: XNA Framework XML usage on 360

jwraith

Yes, I have.

I think I need to clarify a bit more.

I understand how to make the XML serialization of an object on the 360, but I don't want that.

I want to be able to read and parse an XML file into an XmlDocument.




Re: XNA Framework XML usage on 360

Jim Perry

Well, I did some quick experimentation and came up with something that works. Check out my blog entry here.




Re: XNA Framework XML usage on 360

jwraith

Thank you :)




Re: XNA Framework XML usage on 360

Gloei

I am currently using XML in my project and for me it works fine on the 360 and PC, although I use a different approach than Jim. I do it like this:

XmlDocument doc = new XmlDocument();
doc.Load("somedocument.xml");

// now simply access the whole tree using childnodes, attributes, value etc...

foreach (XmlNode node in doc.ChildNodes)
if (node.Name == "test")
{
// do something fancy...
}

This seems to work okay on 360 and PC.





Re: XNA Framework XML usage on 360

Jim Perry

If you don't have a lot of nodes in the XML file that would be fine, but if you have something like 50 nodes that you need to iterate through it might get a little messy with 50 if statements. Depending on the content of the node you could just pass the XmlReader or XmlNode to a class constructor or function or some such and make it a little neater.




Re: XNA Framework XML usage on 360

mattjb

This works on the 360 as well, not sure of the performance implications though...

System.XML.XmlDocument xmlDoc;
System.XML.XmlNode xmlNode;

xmlDoc = new System.Xml.XmlDocument();
xmlDoc.Load("myXMLFile.xml");

xmlNode = xmlDoc.SelectSingleNode("/xpath/to/your/node/and/@attribute");

XPATH info at http://msdn2.microsoft.com/en-us/library/ms256086.aspx

-MB





Re: XNA Framework XML usage on 360

Jim Perry

I thought I had tried using the SelectSingleNode method in the 360 project and it wouldn't compile/run. That's usually how I do it and was surprised that it didn't work.




Re: XNA Framework XML usage on 360

nobodyman

One approach that I thought was kinda neat was the way settings are handled on the "SpaceWar Starter Kit". Check out the Settings.cs and Settings.xml file. The xml format just a serialized XML object. The advantage to doing this is that your settings that can be easily tweaked, yet you get your parsing "for free". So long as you adhere to the xmlserializer's syntax rules for encoding numbers, lists, etc. parsing your file is as easy as:

Stream stream = File.OpenRead(filename);
XmlSerializer serializer = new XmlSerializer(typeof(MyConfigSettingsClass));
MyConfigSettingsClass settings = serializer.Deserialize(stream);


Done deal. It's used for basic settings in space war, but I use it to describe nested datatypes too. The config settings for my parallax scrolling backgrounds. Perhaps not the "prettiest" approach, but definitely the quickest way to get off the ground.