private void ProcessNode(XmlReader reader, Tileset tileset)
        {
            Tile t = this.GenerateTile(reader);
            if (t == null)
                throw new ApplicationException("Unable to create tile for '" + reader.Name + "', there's nothing to handle this!");

            // TODO: This might need to be changed depending on whether a tileset can have multiple tiles in the same position.
            int x = (int)t.X / Tileset.TILESET_CELL_WIDTH;
            int y = (int)t.Y / Tileset.TILESET_CELL_HEIGHT;
            int z = tileset.DepthAt[x, y];
            tileset[x, y, z] = t;
            tileset.DepthAt[x, y] += 1;
        }
 private Tileset LoadXml(string mode, string filename)
 {
     Tileset tileset = new Tileset();
     using (XmlReader reader = XmlReader.Create(filename))
     {
         while (reader.Read())
         {
             switch (reader.NodeType)
             {
                 case XmlNodeType.Element:
                     if (reader.Name.ToLower() == "level")
                         this.m_Current = XmlLoadMode.Root;
                     else if (reader.Name.ToLower() == mode.ToLower() + "solids")
                         this.m_Current = XmlLoadMode.Solids;
                     else if (reader.Name.ToLower() == mode.ToLower() + "tiles")
                     {
                         this.m_Current = XmlLoadMode.Tiles;
                         this.m_TilesetType = reader.GetAttribute("tileset").ToLower();
                     } else if (reader.Name.ToLower() == mode.ToLower() + "entities")
                         this.m_Current = XmlLoadMode.Entities;
                     else if (reader.Name.ToLower().EndsWith("solids") ||
                         reader.Name.ToLower().EndsWith("tiles") ||
                         reader.Name.ToLower().EndsWith("entities"))
                         this.m_Current = XmlLoadMode.Ignore;
                     else if (this.m_Current != XmlLoadMode.Ignore)
                         this.ProcessNode(reader, tileset);
                     break;
                 case XmlNodeType.EndElement:
                     if (reader.Name.ToLower() == "level" || reader.Name.ToLower() == mode.ToLower() + "solids" ||
                         reader.Name.ToLower() == mode.ToLower() + "tiles" || reader.Name.ToLower() == mode.ToLower() + "entities" ||
                         reader.Name.ToLower().EndsWith("solids") || reader.Name.ToLower().EndsWith("tiles") ||
                         reader.Name.ToLower().EndsWith("entities"))
                         this.m_Current = XmlLoadMode.Root;
                     break;
             }
         }
     }
     return tileset;
 }