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 9225837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:40:44+00:00 2026-06-18T04:40:44+00:00

I have come across a problem, I need to basicly deserialize this: <?xml version=1.0

  • 0

I have come across a problem, I need to basicly deserialize this:

<?xml version="1.0" encoding="UTF-8"?>
<api_data>
  <status>ok</status>
  <sessions>
    <id>2</id>
    <sessionID>6bfd1f1a7e87a8a6ed476234ad1d6e86</sessionID>
    <gameID>1</gameID>
    <maxPlayers>8</maxPlayers>
    <hostIP>12.0.0.1</hostIP>
    <hostPort>1993</hostPort>
    <inProgress>0</inProgress>
    <timestamp>1358894690</timestamp>
  </sessions>
  <sessions>
    <id>3</id>
    <sessionID>eeb4dc2df32f885c2b7d13f28a246830</sessionID>
    <gameID>1</gameID>
    <maxPlayers>8</maxPlayers>
    <hostIP>12.0.0.1</hostIP>
    <hostPort>1993</hostPort>
    <inProgress>0</inProgress>
    <timestamp>1358894732</timestamp>
  </sessions>
</api_data>

And I need to convert that to usable data, its also dynamic, so there could be more than just 2 session elements, there could be 4, 20, or 0, the code I have now is just broken, and I was wondering whats a good method to get this to work?

Currently I am up to the point of the XDocument class, with all this loaded.
And I need to return a multi-dimensional array with this data.

EDIT:

Current code, completely broken:

var xmlSessions = xmlDATA.Descendants("api_data").Elements("sessions").Select(x => x);

result = new string[xmlDATA.Descendants("api_data").Count(), 7];

EDIT 2:
More info

The way I was thinking the MultiDimensional Array would be is as follows:

array[0,0] "ok" //Status
array[1,0 to 7] //First Session details go here
array[2,0 to 7] //Second session details go here, and so forth.
  • 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-06-18T04:40:45+00:00Added an answer on June 18, 2026 at 4:40 am

    You can define the following class representations:

    public class api_data
    {
        public string status { get; set; }
    
        [XmlElement]
        public session[] sessions { get; set; }
    }
    
    public class session
    {
        public int id { get; set; }
        public string sessionID { get; set; }
        public int gameID { get; set; }
        public int maxPlayers { get; set; }
        public string hostIP { get; set; }
        public int hostPort { get; set; }
        public int inProgress { get; set; }
        public int timestamp { get; set; }
    }
    

    The key is the [XmlElement] tag on the sessions property, that will instruct the XmlSerializer to read/write XML using the schema sample you provided. To deserialize it, you can use the XmlSerializer as such:

    //this might change, not sure how you obtain your xml, 
    //but let's assume you already have it available as a string
    byte[] xmlBytes = System.Text.Encoding.UTF8.GetBytes(xmlData); 
    
    var stream = new MemoryStream(xmlBytes);
    XmlSerializer serializer = new XmlSerializer(typeof(api_data));
    api_data apidata = (api_data)serializer.Deserialize(stream);
    

    Don’t need any more XML adornment or setup than that to read it in (tested and working).

    EDIT: Though you may want to consider using some other XML attributes to transfer to some nicer naming conventions, and we can also List<Session> to boot instead of an array:

    [XmlRoot("api_data")]
    public class ApiData
    {
        [XmlElement("status")]
        public string Status { get; set; }
    
        [XmlElement("sessions")]
        public List<Session> Sessions { get; set; }
    }
    
    public class Session
    {
        [XmlElement("id")]
        public int ID { get; set; }
    
        [XmlElement("sessionID")]
        public string SessionID { get; set; }
    
        [XmlElement("gameID")]
        public int GameID { get; set; }
    
        [XmlElement("maxPlayers")]
        public int MaxPlayers { get; set; }
    
        [XmlElement("hostIP")]
        public string HostIP { get; set; }
    
        [XmlElement("hostPort")]
        public int HostPort { get; set; }
    
        [XmlElement("inProgress")]
        public int InProgress { get; set; }
    
        [XmlElement("timestamp")]
        public int TimeStamp { get; set; }
    }
    

    EDIT: Just noticed that you need to turn this into a multidimensional array (not sure why, but you specify that’s legacy). Well at this point, you have a nice object model from which you can do this data transfer. Not sure how you do the typing, but let’s just assuming object type array for now:

    ApiData apiData = DeserializeMyApiData(); // from above
    array[0][0] = apiData.Status;
    for(int i = 1; i <= apiData.Sessions.Count; i++)
    {
        var session = apiData.Sessions[i - 1];
        array[i] = new object[8];
        array[i][0] = session.ID;
        array[i][1] = session.SessionID;
        array[i][2] = session.GameID;
        array[i][3] = session.MaxPlayers;
        array[i][4] = session.HostIP;
        array[i][5] = session.HostPort;
        array[i][6] = session.InProgress;
        array[i][7] = session.TimeStamp;
    }
    

    That will go through and build up your array regardless of how many sessions you have.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using $SUB for the first time and have come across this problem.
Have just come across a problem where I believe this is the solution. At
I have come across this problem a few times and never been able to
Really hope this can be done but I have come across a problem I
Sometimes I come across this problem where you have a set of functions that
I have come across a problem. There are N piles of stones where the
I am new to sql and I have come across a problem on joining
I've started learning JSF2.0, and have come across a problem. Any advice on how
I have come across an annoying problem. I have made a system and now
I have come across a strange problem which I would like to get your

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.