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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:28:53+00:00 2026-06-13T14:28:53+00:00

I have to create a very specific shape XML file dynamically within C# to

  • 0

I have to create a very specific shape XML file dynamically within C# to power a flash object on a website. The problem I have faced with many of my attempts is that most output wants each node to have some way of unique identification, I do not want that. Rather the below is the output I am going after, not the output I currently can get. Note it is also invalid XML.

<data>
    <Annual Enrollment>
        <row>
            <column>value1</column>
            <column>value2</column>
            <column>value3</column>
        </row>
        <row>
            <column>value1</column>
            <column>value2</column>
            <column>value3</column>
        </row>
    </Annual Enrollment>
    <Pre-College>
        <row>
            <column>value1</column>
            <column>value2</column>
            <column>value3</column>
        </row>
        <row>
            <column>value1</column>
            <column>value2</column>
            <column>value3</column>
        </row>
    </Pre-College>

….AND so forth. The node titles or and cannot change, nor can the roots for each tree.

The code I have so far looks like this, in my head it seems like it should work, however it does not.

  var tableResult = DashboardData.GetMetricData(1);
  // Outlinining structure
  XDocument document = new XDocument(
       new XDeclaration("1.0", "utf-8", null),
       new XElement("data",
            new XElement("AnnualEnrollment"),
            new XElement("Pre-College"),
            new XElement("Summary")
            ));
  // Now I need to append children to each of the three nodes within the root "data"
  foreach (DataRow row in tableResult.Tables[0].Rows)
  {
      document.Element("AnnualEnrollment").Add(new XElement("row"));

      foreach (var item in row.ItemArray)
      {
          var element = new XElement("column", item);


      }
  }
  • 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-13T14:28:54+00:00Added an answer on June 13, 2026 at 2:28 pm

    Sample below reads rows from first table and converts them to row elements, providing as content columns values converted to column elements.

    XDocument document = new XDocument(
        new XDeclaration("1.0", "utf-8", null),
        new XElement("data",
            new XElement("AnnualEnrollment", 
                from row in tableResult.Tables[0].AsEnumerable()
                select new XElement("row", 
                    from column in tableResult.Tables[0].Columns.Cast<DataColumn>()
                    select new XElement("column", row[column]))),
            new XElement("Pre-College"), // same for pre-college table
            new XElement("Summary") // and same for summary
            ));
    

    Also I’d extracted DataTable conversion into separate (extension) method:

    public static object ToXml(this DataTable dataTable)
    {
        return from row in dataTable.AsEnumerable()
               select new XElement("row",
                          from column in dataTable.Columns.Cast<DataColumn>()
                          select new XElement("column", row[column]));
    }
    

    Now your Xml generation will look like:

    XDocument document = new XDocument(
        new XDeclaration("1.0", "utf-8", null),
        new XElement("data",
            new XElement("AnnualEnrollment", tableResult.Tables[0].ToXml()),
            new XElement("Pre-College", tableResult.Tables[1].ToXml()),
            new XElement("Summary", tableResult.Tables[2].ToXml()) 
            ));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very specific problem, and a work around solution will not help.
I am trying to create a very basic sprite image. First off i have
I'm trying to create a very simple REST server. I just have a test
My knowledge of regex is very weak. So far I have manage to create
I have a very simple line graph I'm trying to create in gRaphael. My
I have a very simple table with two columns, but has 4.5M rows. CREATE
This is a very general question but it's based on a specific problem. I've
I need to create a specific shape for the Tab. It should look like
We have a database with a very simple schema: CREATE TABLE IF NOT EXISTS
this is a very specific question, but i also have very specific details on

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.