Click here to Skip to main content
13,151,514 members (47,201 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I am building a world editor for a game and I need help with the process of loading a map file. Everything is complete except for the map loading. I know how to load xml in c++ using tinyxml but my c# is really rusty. I just need to know how to take data from each of the elements so I can use them in the world editor. Any help would be massively appreciated.

this is an example of the file I am trying to load into my editor.
I know the layout of the xml is pretty poorly designed but I cannot modify it because I can not change the game client's LoadMap function.

<br />
<pre lang="text"><?xml version="1.0" encoding="UTF-8"?><br />
-<Map> -<tileset progPath="../../../../../../../../Desktop/TestTileset.png" <br />
	path="Desktop/TestTileset.png" tileSetSizeY="20" tileSetSizeX="20" tileHeigh="32" tileWidth="32" GridSizeH="5" GridSizeW="5"><br />
		tilesetinfo<br />
		<tileset index="0" y="0" x="0">tile</tileset><br />
		<tileset index="0" y="1" x="0">tile</tileset><br />
		<tileset index="0" y="2" x="0">tile</tileset><br />
		<tileset index="0" y="0" x="1">tile</tileset><br />
		<tileset index="0" y="1" x="1">tile</tileset><br />
		<tileset index="0" y="2" x="1">tile</tileset><br />
</tileset> <br />
 <item y="36" x="40" lane="2">waypoint</item><br />
 <item y="116" x="23" lane="2">waypoint</item><br />
 <item y="116" x="23" lane="2">node</item><br />
 <item y="120" x="72" lane="2">waypoint</item><br />
 <item y="120" x="72" lane="2">node</item><br />
 <item y="114" x="120" lane="2">waypoint</item><br />
 <item y="114" x="120" lane="2">node</item><br />
 <item y="70" x="138" lane="2">waypoint</item><br />
 <item y="116" x="23" lane="2" owner="1">tower</item><br />
 <item y="114" x="120" lane="2" owner="2">tower</item><br />
 <item y="30" x="117" owner="1">avatar</item><br />
 <item y="126" x="125" owner="2">avatar</item><br />
Posted 15-Nov-12 3:50am
Carl Sr101

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This is my short overview of what you can use:

  1. Use System.Xml.XmlDocument class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.

  2. Use the class System.Xml.XmlTextReader; this is the fastest way of reading, especially is you need to skip some data.

  3. Use the class System.Xml.Linq.XDocument; this is the most adequate way similar to that of XmlDocument, supporting LINQ to XML Programming.

I don't clearly see from your question if you can define the file format by yourself or not. If you can, which seems likely, you don't have to work with XML directly at the level of the application. You should abstract out the data model from its persistence using serialization. Then I would advise to work only with the Data Contract:[^].

Please see also my past answers:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating property files...[^].


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170924.2 | Last Updated 15 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100