Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a snake game with three objects: apple, pear & orange. I would like these to be associated with questions which I'm trying to create in XML. This is what I've done so far...

<?xml version="1.0" encoding="utf-8" ?>
<Asset Type="System.Collections.Generic.List[System.String]">


<Question Value ="What is 3 x 3? Orange = 9, Pear = 10, Apple = 12" Right ="orange">
    <answer Value ="orange"/>
    <answer Value ="pear"/>
    <answer Value ="apple"/>


I'm getting the error: "Error There was an error while deserializing intermediate XML. 'Element' is an invalid XmlNodeType. Line 7, position 6."

I'm guessing it's because of the line MathsQuiz but not sure.

Any help is much appreciated!

Thanks, Tom

share|improve this question
I don't think that XML structure fits the List<string> type. The XmlSerializer is probably having trouble with that. – Michael Coleman Apr 19 '11 at 14:03

Much like this question, you cannot simply make up the XML format!

You have to use a format which matches the objects you will be deserializing!

Just as in my answer to that question, you can simply create some of your objects, serialize them, and see what they should look like in XML such that they can be deserialized. For example:

var sb = new StringBuilder();
using(XmlWriter writer = XmlWriter.Create(sb))
    IntermediateSerializer.Serialize(writer, theRootObjectYouAreSerializing, null);

So in your case, if your question structure looks like this:

struct Question
    public string question; 
    public string correct;
    public List<string> answers;

Then your XML will look something like this:

<?xml version="1.0" encoding="utf-8"?>
<Asset Type="MyNamespace.Question">
    <question>What is 3 x 3? Orange = 9, Pear = 10, Apple = 12</question>
share|improve this answer
Thanks for the reply. I'm a real beginner in terms of programming. I knew the XML document had to have a certain layout, I've missed some of the coding you have put. I tried to make it so that text was output just as a test, which worked when making just "<Items>" but wouldnt work the extra elements. Would I need a class for read and write to complete this XML? Thanks again. – Tom Apr 19 '11 at 16:28
Also, your example above is for one question. My game will have multiple questions. How would that be implemented? – Tom Apr 19 '11 at 16:50
Use a list of questions. The Type would be "System.Collections.Generic.List[YourNamespace.Question]" – Michael Coleman Apr 19 '11 at 18:04
@Tom: What Omnion said. Remember to use IntermediateSerializer.Serialize to check these things. – Andrew Russell Apr 20 '11 at 4:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.