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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:28:42+00:00 2026-06-03T19:28:42+00:00

Possible Duplicate: Use LINQ to read all nodes from XML I am trying to

  • 0

Possible Duplicate:
Use LINQ to read all nodes from XML

I am trying to read an XML file using Linq in C# windows application. The sample of the xml string is given below.

<Root>
<Name>John Doe</Name>
<Data>FBCCF14D504B7B2DBCB5A5BDA75BD93B</Data>
<customer>true</customer>
<Accounts>1</Accounts>
<dataSet>
     <Type1>Found matching records.</Type1>
    <Type2>No matches found.</Type2>
   <Type3>Found matching records.</Type3>
</dataSet>
</Root>

I want to display all the data inside the <dataset> tag and <datatag> i want to read <customer> tag as well.

I have created a class with members (string type, string status). Where in type i want to store the type1, 2…and in status i want to store what is inside the type node.

I am able to accomplish this but in the code i have to give


type1 = (string)row.Element("type1"),
type2=(string)row.Element("type2"),

i want to have a generic code in which i dont have to mention every type. In other words i want to read all the child nodes of tag whithout mentioning the tag name. I have spent 2 hours searching for this on google, but haven’t found anything yet.

Expected output

save the information in class object (type and status).

And i want to read the customer tag so that i can know whether the person is already a customer

Any help will be very much appreciated.

Thanks

Update

According to inputs received from Raphaël Althaus

I have the following code:

var list = xml.Descendants("dataSet").Elements()
            .Select(m => new CustomerInfo
                             {
                                 Type = m.Name.LocalName,
                                 Value = m.Value
                             }).ToList();


        foreach (CustomerInfo item in list)
        {
            MessageBox.Show(item.Type+ "   "+item.Value);

        }

and for reading the Customer tag i have written more code.

var isCustomer = from customer in xmlDoc.Descendants("Root")
            select new
            {
              customer = tutorial.Element("customer").Value,
            }

Can i do both in one query?. Or this method is not so heavy on performance, so i can use this?

  • 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-03T19:28:45+00:00Added an answer on June 3, 2026 at 7:28 pm

    something like that ?

    var q = xml.Descendants("dataSet").Elements()
                .Select(m => new
                                 {
                                     type = m.Name.LocalName,
                                     value = m.Value
                                 }).ToList();
    

    You can also directly populate a list of your “class with members”

    var list = xml.Descendants("dataSet").Elements()
                    .Select(m => new <TheNameOfYourClass>
                                     {
                                         Type = m.Name.LocalName,
                                         Value = m.Value
                                     }).ToList();
    

    EDIT :

    to get the “customer” value, I would do another query

    var customerElement = xml.Element("customer");
    var isCustomer = customerElement != null && customerElement.Value == "true";
    

    So you could mix all of that it in a little function

    public IList<YourClass> ParseCustomers(string xmlPath, out isCustomer) {
        var xml = XElement.Load(xmlPath);
        var customerElement = xml.Element("customer");
        isCustomer = customerElement != null && customerElement.Value == "true";
        return xml.Descendants("dataSet").Elements()
                        .Select(m => new <YourClass>
                                         {
                                             Type = m.Name.LocalName,
                                             Value = m.Value
                                         }).ToList();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Concat all strings inside a List<string> using LINQ I am using C#
Possible Duplicate: Why use a framework with PHP? Hi, usually all the projects I
Possible Duplicate: When to use virtual destructors? If all the data members of a
Possible Duplicate: To use Wordpress for developing a web application? For instance, I've been
Possible Duplicate: How do I use LINQ Contains(string[]) instead of Contains(string) Suppose I have
Possible Duplicate: Use of var keyword in C# What is the benefit of using
Possible Duplicate: Use created attribute with javascript in select list im trying to access
Possible Duplicate: Use Visual Studio web.config transform for debugging I have an asp.net application
Possible Duplicate: Use of var keyword in C# Which one is better? using var
Possible Duplicate: Use autorelease when setting a retain property using dot syntax? What is

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.