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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:13:32+00:00 2026-05-11T22:13:32+00:00

I have an xml like the following <DataCollection> <Data> <Name>John</Name> <Age>30</Age> </Data> … more

  • 0

I have an xml like the following

<DataCollection>
  <Data>
    <Name>John</Name>
    <Age>30</Age>
  </Data>
  ... more person
</DataCollection>

I want to create an object (or some type) collection with Name, Age as fields. One problem that I have is I don’t know the structure before hand (all I know is, there will be DataCollection and Data) to create a class and then using linq to use select new. Current implementation, I am walking the XML for each Data, read the elements and create a comma separated list.

Is there a better way to do this? The purpose of the XML is to display all the data that is coming in under Data in a data grid.

  • 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-11T22:13:33+00:00Added an answer on May 11, 2026 at 10:13 pm

    FWIW here’s the LINQ query that’ll turn that XML document into a collection of objects:

        var coll = from XElement c in doc.Descendants("Data") 
           select new { 
               Name = c.Element("Name").Value, 
               Age = int.Parse(c.Element("Age").Value) 
           };
    

    But I think what you’re really looking for is a way to bind the XML document to a DataGrid directly. One way to do that is to bind your DataGrid to a DataTable and use its WriteXml/ReadXml methods to read/write the file.

    On preview … I missed the requirement that the structure of the incoming XML is unknown. You can build up a collection of collections of objects without knowing the structure of the Data blocks using this LINQ:

    var coll = from XElement c in loaded.Descendants("Data")
           select (from XElement d in c.Elements() select d.Value);
    

    Or you can generate the CSV with this:

    string csv = string.Join(Environment.NewLine, 
    ( from XElement c in loaded.Descendants("Data") 
      select string.Join(",", 
        (from XElement d in c.Elements() select d.Value).ToArray())
    ).ToArray());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have XML with a value like the following: <products> <product id=1 name=All Products>
I have a simple xml document that looks like the following snippet. I need
I have the following xml I'd like to deserialize into a class <?xml version=1.0
I have an xml file like this: <root> <item> <name>one</name> <status>good</status> </item> <item> <name>two</name>
So I have xml that looks like this: <todo-list> <id type=integer>#{id}</id> <name>#{name}</name> <description>#{description}</description> <project-id
Let's say I have some XML like this <channel> <item> <title>This is title 1</title>
Greetings! I have some XML like this: <Root> <AlphaSection> . . . </AlphaSection> <BetaSection>
Greetings! I have some XML like this: <Root> <MainSection> <SomeNode>Some Node Value</SomeNode> <SomeOtherNode>Some Other
I have a XML File like that <?xml version=1.0 encoding=utf-8 ?> <Configurations> <EmailConfiguration> <userName>xxxx</userName>
I have normally hand written xml like this: <tag><?= $value ?></tag> Having found tools

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.