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

  • Home
  • SEARCH
  • 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 6138891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:55:20+00:00 2026-05-23T17:55:20+00:00

I have an XElement, called XUsers, that will contain XML which looks like this:

  • 0

I have an XElement, called “XUsers”, that will contain XML which looks like this:

<users>
   <user id="12345" name="Bob Smith" />
   <user id="67890" name="Jamal Stevens" />
   <user id="54321" name="Mary Jones" />
</users>

…and another XElement, called “XTasks”, that will contain data like this:

<tasks>
   <task id="1" title="Task 1" ownerId="54321" />
   <task id="2" title="Task 2" ownerId="12345" />
   <task id="3" title="Task 3" ownerId="67890" />
</tasks>

I want to add an attribute (“ownerName”) to the task elements in the second XElement (XTasks), and set its values according to a “join” with the first XElement (XUsers). So, my final result will be that the XML in XTask will look like this:

<tasks>
   <task id="1" title="Task 1" ownerId="54321" ownerName="Mary Jones" />
   <task id="2" title="Task 2" ownerId="12345" ownerName="Bob Smith" />
   <task id="3" title="Task 3" ownerId="67890" ownerName="Jamal Stevens" />
</tasks>

Is this possible using Linq? I haven’t been able to find any examples of this sort of operation on the web. What is the most efficient way to accomplish this in my ASP.NET(C#) code?

Thanks for any advice you can give.

  • 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-23T17:55:21+00:00Added an answer on May 23, 2026 at 5:55 pm

    I am doing this without any IDE in front of me, so forgive me for any errors..

     foreach (XElement task in XTasks.Elements())
     {
         XElement userNode = XUsers.Elements().Where(
            e => e.Attribute("id").Value == task.Attribute("ownerId").Value).FirstOrDefault();
         if (userNode != null)
         {
            task.Attribute("ownerName").SetValue(userNode.name);
         }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XElement that looks like this; <VideoFiles> <VideoFileInfo> <VideoType>1000</VideoType> <FormatCode>1000</FormatCode> <Url>http://www.idontwantthisvalue.com</Url> </VideoFileInfo>
I have an Xml Stream that I'd like to read into an XElement .
I have a XML Like this: <?xml version=1.0 encoding=utf-8?> <soap:Envelope xmlns:soap=http://www.w3.org/2003/05/soap-envelope xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:xsd=http://www.w3.org/2001/XMLSchema> <soap:Body>
I have an XML file that is loaded into an XElement. I want to
I have an XElement and inside that element I have another XML fragment. How
In C#, assume that I have an XElement (say myXElement ) containing some XML
I have an XElement variable named content which consists of the following XML: <content>
I have a XElement that maps like follows: <book> <author>sadfasdf</author> <title>asdfasdf</title> <year>1999</year> </book> <book>
I have an xml (called xdoc) file like the following: <Root> <ItemContainer> <Item> <Item>
I have a class that parses an XML document in C# using XElement. I

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.