Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3626974
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:49:47+00:00 2026-05-18T23:49:47+00:00

I am trying to use an XML file to store my high score, here

  • 0

I am trying to use an XML file to store my high score, here is my high score class

[Serializable]
public struct HighScoreData {
    public string[] PlayerName;
    public int[] Score;
    public int[] Level;

    public int Count;

    public HighScoreData(int count) {
        PlayerName = new string[count];
        Score = new int[count];
        Level = new int[count];

        Count = count;
    }
}

And here is my XML file :

<?xml version="1.0" encoding="utf-8" ?>
<XnaContent>
<!-- TODO: replace this Asset with your own XML asset data. -->
<Asset Type="Cellular.HighScoreData">
        <PlayerName>
            <Item>1</Item>
            <Item>2</Item>
            <Item>3</Item>
            <Item>4</Item>
            <Item>5</Item>
            <Item>6</Item>
            <Item>7</Item>
            <Item>8</Item>
            <Item>9</Item>
            <Item>10</Item>
        </PlayerName>
        <Score>
            <Item>1</Item>
            <Item>2</Item>
            <Item>3</Item>
            <Item>4</Item>
            <Item>5</Item>
            <Item>6</Item>
            <Item>7</Item>
            <Item>8</Item>
            <Item>9</Item>
            <Item>10</Item>
        </Score>
        <Level>
            <Item>1</Item>
            <Item>2</Item>
            <Item>3</Item>
            <Item>4</Item>
            <Item>5</Item>
            <Item>6</Item>
            <Item>7</Item>
            <Item>8</Item>
            <Item>9</Item>
            <Item>10</Item>
        </Level>
        <Count>10</Count>
</Asset>

Here is my method to Load the data from XML

    public void LoadStoredHighScore() {
        FileStream stream = File.Open(HighScoreFile, FileMode.Open, FileAccess.Read);
        try {
            XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData));
            highScoreList = (HighScoreData) serializer.Deserialize(stream);
        } finally {
            stream.Close();
        }
    }

in “highScoreList = (HighScoreData) serializer.Deserialize(stream);” this line,
it gives me exception “There is an error in XML document (0, 0).”
with inner exception “Root element is missing”.

Am I doing anything wrong?
Any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T23:49:48+00:00Added an answer on May 18, 2026 at 11:49 pm

    First off, the serializer will look for a root element named as the type you are trying to deserialize, which it cannot find.

    Next, you cannot deserialize into this structure since it have no default constructor. The serializer have no way of figuring out what to pass as the count parameter. Read up on this article to get further details.

    Here’s a suggested root structure:

    <?xml version="1.0" encoding="utf-8" ?>
    <HighScoreData>
        <PlayerName>
        ...
    </HighScoreData>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to find an XML file I can use in lieu of a look-up
I'm trying to use XML documentation on the members of a class, and in
Trying to use an excpetion class which could provide location reference for XML parsing,
I'm trying to use the lxml library to parse an XML file...what I want
I am trying to use URLLoader to load an XML file from server (same
im trying to use libxml2.2 to parse an XML file in my iPhone app
I am trying to use an XMLHTTPRequest to download an .xml file and add
I'm trying to use JAXB to pull some elements from a large XML file
I'm trying to use Nokogiri to grab some data from an XML file, then
I am working on an Actionscript 2 project - trying to use the XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.