XNA Creators Club Online
Page 1 of 1 (2 items)
Sort Posts: Previous Next

ContentTypeWriter vs XMLWriter?

Last post 12/06/2009 16:54 by Shawn Hargreaves. 1 replies.
  • 12/06/2009 15:01

    ContentTypeWriter vs XMLWriter?

    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 :)
  • 12/06/2009 16:54 In reply to

    Re: ContentTypeWriter vs XMLWriter?

    The Content Pipeline approach (which uses ContentTypeWriter and ContentTypeReader to handle the .xnb file format) works fine on Xbox.

    You can also use many of the various .NET XML technologies (such as XmlReader, XmlDocument, or XmlSerializer) but these aren't really direct equivalents of the Content Pipeline system: they are different technologies with somewhat different purposes (although all of them are capable of reading and writing data to files on disk).
    XNA Framework Developer - blog - homepage
Page 1 of 1 (2 items) Previous Next