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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:44:17+00:00 2026-05-28T05:44:17+00:00

Deal all, Assume I have a XML file and I need to parse it

  • 0

Deal all,

Assume I have a XML file and I need to parse it to objects (DTOs). Example:

<Root>
  <Item>
    <X>1</X>
    <Y>2</Y>
  <Item>
</Root>

And I have a DTO object:

public class Item
{
  public int X{get;set;}
  public int Y{get;set;}
  public int Z{get;set;}
}

To create a Item object, I need to know X and Y, and I will set Z = X*Y

I use LINQ to parse XML to objects:

XDocument reportDoc = XDocument.Load(@"Report.xml");
var query = from item in reportDoc.Element("Root").Descendants()
select new Item()
{
   X = Convert.ToInt32(item.Element("X").Value),
   Y = Convert.ToInt32(item.Element("Y").Value)
   // Z = X*Y -> I can't do this by this statement
};

Please help me how to set value to Z property directly in LINQ select statement. Thanks.

  • 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-28T05:44:17+00:00Added an answer on May 28, 2026 at 5:44 am

    You can use the let clause to declare intermediate variables:

    XDocument reportDoc = XDocument.Load(@"Report.xml");
    var query = from item in reportDoc.Element("Root").Descendants()
    let x = Convert.ToInt32(ticket.Element("X").Value)
    let y = Convert.ToInt32(ticket.Element("Y").Value)
    select new Item()
    {
       X = x,
       Y = y
       Z = x * y
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I often have to deal with XML documents that contain namespaced elements, but doesn't
I have an application that is supposed to deal with all kinds of characters
Assume you have five products, and all of them use one or more of
Hey all, here's the deal... I've got a UIImage that is being loaded in
Hey all. I am using sifr 2.0.7 and here's the deal. The sifr is
With HRD and BigTable, you are forced to deal with eventual consistency for all
I do have to deal with very large plain text files (over 10 gigabytes,
How do you deal with user input (unicode) that you need to be restricted
I need to deal with a counter that gives me ticks for my application.
I have a web application which uses URLs that look like this: http://library.example.com/Register.aspx?query=academic&key=586c70bb-5683-419c-aae9-e596af9ab66a (The

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.