1
\$\begingroup\$

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?

\$\endgroup\$
4
  • \$\begingroup\$ Are you planning on loading it using the content loader, or is it dynamic data loaded at run-time? \$\endgroup\$
    – William
    Feb 9, 2012 at 23:19
  • 1
    \$\begingroup\$ 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.) \$\endgroup\$ Feb 9, 2012 at 23:21
  • \$\begingroup\$ @MindWorX Yes, i'm planning on loading this through the content-loader. And Richard, I see your point. \$\endgroup\$
    – dan369
    Feb 9, 2012 at 23:45
  • \$\begingroup\$ I'd totally upvote that if it was an answer \$\endgroup\$
    – Jimmy
    Feb 10, 2012 at 0:17

3 Answers 3

3
\$\begingroup\$

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();
\$\endgroup\$
0
\$\begingroup\$

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 :)

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .