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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:09:03+00:00 2026-05-31T02:09:03+00:00

I have an XML File with Elements that look like the following: <level> <name>Name

  • 0

I have an XML File with Elements that look like the following:

<level>
        <name>Name of Level 1</name>
        <number>1</number>
        <authorTime>8.55</authorTime>
        <scoringTime>20</scoringTime>
        <map width="19" height="15"><!--Level1-->
            <row>0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0</row>
            <row>2,-1,-1,-1,-1,-1,-1,-1,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,2</row>
            <row>2,-1,-1,-1,0,1,0,-1,2,-1,0,-1,-1,-1,-1,-1,0,-1,2</row>
            <row>0,1,0,-1,2,-1,-1,-1,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,2</row>
            <row>2,-1,-1,-1,2,-1,0,1,0,1,0,-1,0,0,-1,0,0,-1,2</row>
            <row>2,-1,0,1,0,-1,-1,-1,2,-1,-1,-1,-1,2,-1,-1,2,-1,2</row>
            <row>2,-1,-1,3,2,-1,0,-1,2,-1,0,-1,-1,2,-1,-1,2,-1,2</row>
            <row>2,-1,0,1,0,0,0,-1,0,-1,0,1,1,0,-1,-1,2,-1,2</row>
            <row>0,1,0,-1,-1,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,-1,2</row>
            <row>2,-1,2,-1,-1,0,1,0,1,0,-1,0,1,0,1,1,0,-1,2</row>
            <row>2,-1,0,0,-1,-1,-1,0,-1,2,-1,2,-1,0,-1,-1,2,-1,2</row>
            <row>2,-1,2,-1,-1,0,-1,-1,-1,2,-1,2,-1,-1,-1,-1,2,-1,2</row>
            <row>2,-1,0,0,-1,0,1,1,1,0,1,0,-1,0,1,1,0,-1,2</row>
            <row>2,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2</row>
            <row>0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0</row>
        </map>
    </level>

And I want to use an XDocument (in C#/XNA) to read the “map” into a 2D rectangular array (y,x) – so in this example case it would be int[15,19].

All I can think of is creating a jagged array and converting to a rectangular one later – something like

int[][] test = ((from level in xDoc.Descendants("level")
                select (from map in level.Element("map")
                            select (from row in map.Elements("row")
                                    select (int.Parse(row.Value))).ToArray()).ToArray()));

But I know I need a string split on commas in here somewhere; and anyway I get a “select not found” error on level.Element(“map”).

My finished array should look like {{0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0},{2,-1,-1,-1,-1,-1,-1,-1,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,2},…

Can anyone help?

–EDIT–

I now have:

    var test = (from level in xDoc.Descendants("level")
                    select (from row in level.Elements("map").Elements("row")
                        select (from col in row.Value.Split(',')
                            select (int.Parse(col))).ToArray()).ToArray());

which is giving me the data I want, but the “test” output is showing up in the debug as being of type: {System.Linq.Enumerable.WhereSelectEnumerableIterator<System.Xml.Linq.XElement,int[][]>}

Getting closer, but still not quite right!

  • 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-31T02:09:05+00:00Added an answer on May 31, 2026 at 2:09 am

    Just make it

    select (from row in map.Elements("row").Value.Split(',')
            select (int.Parse(row) ...
    

    And then it might just make sense to call it col instead of row.

    All I can think of is creating a jagged array and converting to a rectangular one later

    Why convert? A jagged array seems fine.


    Edit

    I gave it a test :

            var test =
                from level in doc.Descendants("level")
                select (from map in level.Elements("map")
                    select (from row in map.Elements("row")
                            select (from col in row.Value.Split(',') 
                              select int.Parse(col)).ToArray()).ToArray() );
    

    Which gives you an IEnumerabl<IEnumerable<int[][]>> (level and map lists).

    So test.First().First() is your first array.

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

Sidebar

Related Questions

I have an XML file that starts like this: <Elements name=Entities xmlns=XS-GenerationToolElements> I'll have
I have an xml file with elements that look like this (abbreviated for clarity):
I have an XML document that looks like this: <file> <name>NAME_OF_FILE</name> </file> <file> <name>NAME_OF_FILE</name>
I have an xml file that contains its element like <ab:test>Str</ab:test> When I am
I've got something like the following XML file. <credits> <property name=tag> <item>v0003</item> </property> <property
I have an XML file with the following elements and attributes: <element> <unit id=1
I have an xml file from an external system that looks like this. <?xml
i have the following XSL that will transform an XML file and basically flatten
I have an xml file with 000's of lines with elements that differ only
I have an XML Schema Definition file .XSD who's elements are in Spanish. I

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.