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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:00:21+00:00 2026-05-27T21:00:21+00:00

I have created new class to read the data from xml file, which looks

  • 0

I have created new class to read the data from xml file, which looks like :

public class Validations
{
  public string id { get; set; }
  public List<string> lhsList { get; set; }
  public List<string> rhsList { get; set; }
}

XML I am trying to read is:

<root>
<Validation id="val3">
    <lhs id='Estimated' />
    <lhs id='Newqurter' />
    <rhs id='Current' />
    <rhs id='FirstQuarter' />
</Validation>
.
.
.

</root>

Code I have written to read the xml is :

List<Validations> vList = new List<Validations>();
vList = (from XElement xele in xdoc.Root.Elements()
  select new Validations
  { 
    id = xele.Attribute("id").Value.ToString(),
    // lhsList = ((xele.Elements().FirstOrDefault(p => p.Name == "lhs").FirstAttribute.Value
    // rhsList = ((xele.Elements().FirstOrDefault(p => p.Name == "rhs").FirstAttribute.Value
  }
).ToList<Validations>();

How do read the List<lhsList> ?
I tried

lhsList = ((xele.Elements().FirstOrDefault(p => p.Name == "lhs").FirstAttribute.Value).ToList(), 

But its not working as expected. What can be other ways to do 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-05-27T21:00:21+00:00Added an answer on May 27, 2026 at 9:00 pm

    You can create the list of lhs elements as follows:

    List<string> lhsElements = xele.Elements("lhs")
                                   .Select(el => el.Attribute("id").Value)
                                   .ToList();
    

    This selects all the lhs elements that are children of xele, then selects the value of their ‘id’ attribute. I’ll leave it to you to work out how to merge this with your code.

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

Sidebar

Related Questions

I am currently trying to read from an xml file which records the jobs
I have a class with a member Address that I read from an XML
I am new to iphone development.I have created a UIview controller class and added
We have created a new List View Style that shows thumbnails from a picture
I have a class with some data members (int, string, bool, Point). These data
I like to ask, how I can read data from my databast test_database.db and
I want to store some data from structures like this: class Project { ChildA
I have a base class called Geometry from which there exists a subclass Sphere
i'd like to read binary data from a blob, using the Stream interface around
i created a method to read a xml file but it doesn't work twice,

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.