Skip to main content
GameDev.net gamedev.net
🔒 Locked

XNA pipeline with XML Listtype

Started by QuadMV Feb 23, 2008 at 10:47 AM 0 replies 3.8k views
Original Post
QuadMV
QuadMV
Hey all, I've written an XNA pipeline routine to process an XML file representing a level in my game. I have a section in the XML file that contains repetitive tags and I've been having a problem figuring out the "right code syntax/xml format" to compile and read it. If someone could review the following small snippets of code and recommend what to try I'd appreciate it: I'm currently receiving a compile error during the XML deserializing: error: Error 1 There was an error while deserializing intermediate XML. 'Element' is an invalid XmlNodeType. Line 26, position 8. C:\devel\BlockBuster\XNA 2.0\BlockBusterXNA2 - single player advanced XML\BlockBusterXNA2\Content\Levels\BlockBUSTERLevel1.xml 26 8 BlockBusterXNA2 When I click on the error it's sitting on the first "b" of as highlighted below Also, within the BLOCKS section, I want to repeat the structure N times, hence the usage of LIST. I also tried with …… but still continue to receive errors. If anyone has any recommendations I’d really appreciate it. ------------------------------------------------- public class Level { public struct sBlockLoadMaster { public int blockid; public string modelname; public float strength; public Vector4 particleexplosioncolor; public string particleexplosiontexture; }; public int levelid = 0; public string levelname = ""; public int leveltype = 0; public List blocks = new List(); } // End Level Class XML File: 1 Training Level 1 0 0 <----------- Error on this line between < and b max9_neongreen_box 15.0 152 251 152 255 destroy // READER public class LevelContentReader : ContentTypeReader { protected override Level Read( ContentReader input, Level existingInstance) { Level level = new Level(); level.levelid = input.ReadInt32(); level.levelname = input.ReadString(); level.leveltype = input.ReadInt32(); level.blocks = input.ReadObject>(); return level; } } // WRITER namespace XMLLevelWriter { #region LevelContentWriter [ContentTypeWriter] public class LevelContentWriter : ContentTypeWriter { protected override void Write( ContentWriter output, Level value) { output.Write(value.levelid); output.Write(value.levelname); output.Write(value.leveltype); output.WriteObject>(value.blocks); } public override string GetRuntimeReader( TargetPlatform targetPlatform) { return typeof(LevelContentReader).AssemblyQualifiedName; } } // Class XMLLevelWriter #endregion // LevelLevelWriter} } // Namespace: XMLLevelWriter
3DMUVE is an amateur game development team, and the designer and developer of a new gaming technology “MUVE” for the gaming industry.
QuadMV
QuadMV
If anyone is interested I got it to work.

I was close, I needed to do a few things:

1. wrap each element in the XML section with



0
max9_neongreen_box
15.0
152 251 152 255
destroy


2
max9_neonblue_box
25.0
152 251 152 255
destroy



2. I changed the BlockLoadMaster from a struct to its own class (maybe a struct would have worked, not sure)

3. similar to the Level declaration, I created a Reader and Writer for the BlockLoadMaster

Here is what I added:

// This is in the separate Level and Reader project along with the LevelClass and Reader (compiled to a DLL)
public class BlockLoadMaster
{
public int blockid;
public string modelname;
public float strength;
public Vector4 particleexplosioncolor;
public string particleexplosiontexture;

}

public class BlockContentReader : ContentTypeReader
{
protected override BlockLoadMaster Read(
ContentReader input,
BlockLoadMaster existingInstance)
{
BlockLoadMaster block = new BlockLoadMaster();

block.blockid = input.ReadInt32();
block.modelname = input.ReadString();
block.strength = (float)input.ReadSingle();
block.particleexplosioncolor = input.ReadVector4();
block.particleexplosiontexture = input.ReadString();

return block;
}
}


//============================================

// This is in the separate writerproject along with the LevelWriter
// (compiled to a DLL)
[ContentTypeWriter]
public class BlockContentWriter : ContentTypeWriter
{
protected override void Write(
ContentWriter output,
BlockLoadMaster value)
{
output.Write(value.blockid );
output.Write(value.modelname);
output.Write(value.strength );
output.Write(value.particleexplosioncolor);
output.Write(value.particleexplosiontexture);
}

public override string GetRuntimeReader(
TargetPlatform targetPlatform)
{
return typeof(BlockContentReader).AssemblyQualifiedName;
}
} // Class BlockContentWriter

3DMUVE is an amateur game development team, and the designer and developer of a new gaming technology “MUVE” for the gaming industry.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.