2
votes

I'm creating an XNA game. I've made it so I can specify all the level details in an XML file which is then de-serialized and used to set up the level details.

At the moment, it's just referencing a file on my computer - my question is, how do I reference this more generically?

Adding the xml in my content folder created a multitude of complaints about schemas and such like, which made me think that likely wasn't the correct route.

Any suggestions?

I tried removing all the entries from the XNA, this gives:

Attempt to access the method failed: System.IO.StreamReader..ctor(System.String)

EDIT:

The xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XnaContent>
  <Asset Type = "RDrop.Level[]">
  <Item>
    (stuff)
  </Item>
  <Item>
    (stuff)   
  </Item>
  </Asset>
</XnaContent>

EDIT:

I've started a new windows phone project - the previous one wasn't one. I've copied everything over and added "dataTypes" ala this tutorial:

http://msdn.microsoft.com/en-us/library/ff604979.aspx

Game project references -> content, MyDataTypes. Content references -> MyDataTypes.

The XML is as is in previous edit and is contained in the content folder via Add-> Existing Item-> Level.XML.

Any ideas?

2
I think you can get more answers on this subject on gamedev.stackexchange.comRicardo Souza
Having re-read this a couple of times I'm not seeing anything that is XNA/game specific. This is just a question about de-serialising some XML.Kev
@Kev This is XnaContent - it's supposed to be built into binary data by the XNA content pipeline's XmlImporter. (As per Robert's answer.)Andrew Russell
Joshua, would you like me to migrate this over to our games dev site, you might get betters eyes on this question?Kev
Robert seems to be on the right track here - though I seem to have opened a can of worms trying to shoe horn this in.Joshua Mee

2 Answers

2
votes

You can leave the build action as "Compile". One method to do what you want is the following:

Create a class that the xml is going to be describing. Example: Level.cs

Then structure your xml file like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XnaContent>
    <Asset Type="The_Level_class_namespace.Level">
        <Property1>Value</Property1>
        <Property2>Value</Property2>
        <Property3>Value</Property3>
        <Property4>Value</Property4>
    </Asset>
</XnaContent>

if you want the xml to describe an array of objects you can do structure the xml like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XnaContent>
    <Asset Type="The_Level_class_namespace.Level[]">
        <Item>
            <Property1>Value</Property1>
            <Property2>Value</Property2>
            <Property3>Value</Property3>
            <Property4>Value</Property4>
        </Item>
    </Asset>
</XnaContent>

From there you just need to make sure your values are in the proper format. For example a vector2 object would be like this:

<Vector2Property>x_value y_value</Vector2Property>

Make sure that your content project references the game project or library project.

Hope this helps :)

0
votes

Open the properties of your XML document (right click in your content folder). You can set the Build Action to : None.

That way, the compiler won't analyse your schema, thus it won't produce any warnings.

(I'm not entirely sure about this, just my first guess)