Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Edit:

So i'm going to rephrase the question a bit, seeing as now i think know how i'm going to read this data. Looking at this example as my guide: http://forums.create.msdn.com/forums/p/53404/323877.aspx

This is pretty much what i'm currently doing, and to be clear and show you guys: http://pastebin.com/GxqQcBDg, that's how i'm loading my data.

So looking at that guys example from his post, he has a similar layout, his "Enemies" can equal my element "Animated_Tiles" and then his "Items" could be equal to my "Tile" objects, at least if you compare my data to his they look extremely similar, and yes i did update the Data as Richard Marskell - Drackir suggested, But i'm wondering if i can have "Type" definitions like the guy has in his example, to show what i mean:

  <Animated_Tiles Type="System.Collections.Generic.List[Namespace.Class]">

Can that be done? Or is it only the "Asset" element that can have the Type definition? Currently this is what my new data layout looks like: http://pastebin.com/i42166ZQ

But currently, it seems to start reading it but i get this error by the first "Tile" Element. So the only difference i see between his & my layouts are that he has the Asset containing the List definition whereas i have "Animated_Tiles". So i'm unsure can any element can have the "Type=Blah" definition?

share|improve this question
    
Are you planning on loading it using the content loader, or is it dynamic data loaded at run-time? –  William 'MindWorX' Mariager Feb 9 '12 at 23:19
1  
Did you make that file? The reason you're having trouble figuring out how to use it is because it was poorly made. If you convert <Tile#> to <Tile id="#">, I think you'll find that it's much easier to read. (Since Animated_Tiles will essentially become an array of Tiles instead of an object with many properties.) –  Richard Marskell - Drackir Feb 9 '12 at 23:21
    
@MindWorX Yes, i'm planning on loading this through the content-loader. And Richard, I see your point. –  dan369 Feb 9 '12 at 23:45
    
I'd totally upvote that if it was an answer –  Jimmy Feb 10 '12 at 0:17

3 Answers 3

You could skip Deserializer and just use Linq to Xml:

var xelement = XElement.Load(file);
var tiles = xelement.Element("Animated_Tiles")
    .Elements()
    .Where(el => el.Name.LocalName.StartsWith("Tile"))
    .Select(el => new Tile {
        PositionX = (int)el.Element("PositionX"),
        PositionY = (int)el.Element("PositionY"),
        Type = el.Element("Type").Value
    })
    .ToArray();
share|improve this answer

Load in the XML file into a DOM tree and then iterate though the tiles.

http://support.microsoft.com/kb/317662

Edit: Or use Jimmy's Idea :)

share|improve this answer
up vote 0 down vote accepted

Well i got it going now :). It seems that i can have other elements using the "Type=Blah" definition, i didn't know that but it's good to know. The Animated_Tiles all needed to be "Items" of the List, i feel stupid :/ make so much sense now that the Elements in the "Animated_Tiles" Element would be required to have the title of Item.

But it works great now :D. Thanks you guys for your answers though.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.