So I've been working on a new project for the last few days, just trying to gain some experience and improve my skills more than anything. Right now I am using a ContentTypeWriter and subsequently a ContentTypeReader. However, what is the difference between these and XMLWriter/Reader? I haven't been able to borrow my brothers Xbox360 yet to do any testing but from some reading, it seems that I may need the XMLWriter/Reader if I wish to compile on the 360 but can I also use it for testing with my PC as it is all I have access to currently? Here is an example of one of my readers:
| 1 |
using System; |
| 2 |
using Microsoft.Xna.Framework; |
| 3 |
using Microsoft.Xna.Framework.Content; |
| 4 |
using Microsoft.Xna.Framework.Graphics; |
| 5 |
|
| 6 |
|
| 7 |
namespace ContentReaders |
| 8 |
{ |
| 9 |
public class TileReader |
| 10 |
{ |
| 11 |
Vector2 gridPosition; |
| 12 |
string texture; |
| 13 |
string objectType; |
| 14 |
int nodeCost; |
| 15 |
|
| 16 |
public string ObjectType |
| 17 |
{ |
| 18 |
get {return objectType;} |
| 19 |
set {objectType = value; } |
| 20 |
} |
| 21 |
|
| 22 |
public string Texture |
| 23 |
{ |
| 24 |
get { return texture; } |
| 25 |
set { texture = value; } |
| 26 |
} |
| 27 |
|
| 28 |
public Vector2 GridPosition |
| 29 |
{ |
| 30 |
get { return gridPosition; } |
| 31 |
set { gridPosition = value; } |
| 32 |
} |
| 33 |
|
| 34 |
public int NodeCost |
| 35 |
{ |
| 36 |
get { return nodeCost; } |
| 37 |
set { nodeCost = value; } |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
//This reads my XML Files that have an associated type (can be seen at the top of the xml file) |
| 42 |
//Each public value and public set/get function must have an associated XML value. |
| 43 |
public class TileContentReader : ContentTypeReader<TileReader> |
| 44 |
{ |
| 45 |
protected override TileReader Read( |
| 46 |
ContentReader input, |
| 47 |
TileReader existingInstance) |
| 48 |
{ |
| 49 |
TileReader sprite = new TileReader(); |
| 50 |
|
| 51 |
sprite.ObjectType = input.ReadString(); |
| 52 |
sprite.Texture = input.ReadString(); |
| 53 |
sprite.GridPosition = input.ReadVector2(); |
| 54 |
sprite.NodeCost = input.ReadInt32(); |
| 55 |
return sprite; |
| 56 |
|
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
} |
Could anyone provide a guide to how to transfer this to XMLReader style (and likewise, how to do XMLWriter) or an article or such showing how it is implemented? I've looked at the MSDN information on these but somehow I rarely feel enlightened from the information there. I'm sure it is really helpful to some people but maybe I'm just not experienced enough to understand it all yet.
And, if I may ask one more related question. I am currently using these just to transfer data from an XML file to values in my game. Could anyone post an article/example of taking data and making it into an xml file? I know I asked a lot of questions but thanks for the help everyone, its always appreciated :)