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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:36:07+00:00 2026-05-14T05:36:07+00:00

I am currently working with a webservice to pull a report about users in

  • 0

I am currently working with a webservice to pull a report about users in a remote support system.

After pulling my report and receiving the result, I am given the following string back by the method:

<report>
    <header>
        <field id="0">Source</field>
        <field id="1">Session ID</field>
        <field id="2">Date</field>
        <field id="3">Name</field>
        <field id="24">Technician Name</field>
        <field id="25">Technician ID</field>
    </header>
    <data>
        <row>
            <field id="0">Email</field>
            <field id="1">55037806</field>
            <field id="2">4/13/2010 2:28:06 AM</field>
            <field id="3">Bill Gates</field>
            <field id="24">John</field>
            <field id="25">1821852</field>
        </row>
        <row>
            <field id="0">Telephone</field>
            <field id="1">55034548</field>
            <field id="2">4/13/2010 12:59:44 AM</field>
            <field id="3">Steve Jobs</field>
            <field id="24">John</field>
            <field id="25">1821852</field>
        </row>
    </data>
</report>

After receiving this string, I need to take it and display the actual data in a datagridview. I’ve tried putting it into an XMLDocument then reading that, but it seems to keep failing. Just interested in another set of eyes 🙂 Application is written in C# in VS2010.

  • 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-14T05:36:08+00:00Added an answer on May 14, 2026 at 5:36 am

    You could use Linq to XML to build a DataTable with the column names from the XML file, then set that table as the DataSource of the DataGridView :

            string xml = theWebService.TheMethod();
            XDocument doc = XDocument.Parse(xml);
            var queryHeaders =
                from field in doc.Root.Element("header").Elements("field")
                select new
                {
                    Id = field.Attribute("id").Value,
                    Name = field.Value
                };
    
            var headers = queryHeaders.ToDictionary(f => f.Id, f => f.Name);
    
            DataTable table = new DataTable();
            foreach (var kvp in headers)
            {
                table.Columns.Add(kvp.Value);
            }
    
            Func<XElement, DataRow> rowGenerator =
                element =>
                {
                    var row = table.NewRow();
                    foreach (var field in element.Elements("field"))
                    {
                        string fieldId = field.Attribute("id").Value;
                        string columnName = headers[fieldId];
                        string value = field.Value;
                        row[columnName] = value;
                    }
                    return row;
                };
    
            var rows =
                from rowElement in doc.Root.Element("data").Elements("row")
                select rowGenerator(rowElement);
    
            foreach (var row in rows)
            {
                table.Rows.Add(row);
            }
    
            dataGridView.AutoGenerateColumns = true;
            dataGridView.DataSource = table;
    

    Note that the code above only works if all fields have distinct names. If that’s not the case, you might want to use the field ID as the DataColumn name, and change the headers of the DGV with the actual field names

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

Sidebar

Related Questions

Am currently working on an application that requires users to submit posts and comments
I'm currently working on desktop application which calls third party API. After authorizing against
I'm currently working on a WebService that is meant to become used by numerous
I am currently working on an Webservice to retrieve a pdf Document from an
I am currently working on a jax-ws webservice which is suppossed to provide internationalised
I am currently working on a document management system in ASP.NET 3.5 using the
I am currently working on a report which has data injected into it from
I'm currently working on a web service using .NET that returns information about the
Currently working with converting SQLException error messages into messages that are more useful for
Currently working with the following package structure: /package __init__.py final.py /write __init__.py write.py /data

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.