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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:29:59+00:00 2026-05-25T02:29:59+00:00

I am newbie in LINQ to XML.I have two variable one and two and

  • 0

I am newbie in LINQ to XML.I have two variable one and two and I want to set these variable values in attribute in XML.

 static void Main(string[] args)
    {
        string one = "first";
        string two = "Second";

        XDocument doc = XDocument.Load(test.xml);

    }

XML

    <Root>
  <Details XIndex="One" Index="">
    <abc></abc>
  </Details>
  <Details XIndex="Two" Index="">
    <xyz></xyz>
  </Details>
</Root>

Now please tell me how I can set One and two variables value in Index attribute in details node.

Example – I want below output.

<Root>
  <Details XIndex="One" Index="First">
    <abc></abc>
  </Details>
  <Details XIndex="Two" Index="Second">
    <xyz></xyz>
  </Details>
</Root>

Please tell me.

Thanks in advance.

  • 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-25T02:30:00+00:00Added an answer on May 25, 2026 at 2:30 am

    You can use the XElement.SetAttributeValue() method:

    var element = doc.Elements("Details")
                     .Single(x=>x.Attribute("XIndex").Value=="One");
    
    element.SetAttributeValue("Index", "First");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Newbie in the Linq to XML arena... I have a Linq query with results,
I have another newbie LINQ question. I have a dataset with two columns. I
I'm a LINQ to XML newbie, and a KML newbie as well; so bear
I'm really a LINQ newbie. I got an unknown problem: public static int save(TEntity
Newbie here...can I write one program which incorporates .NET LINQ and also various Java
I'm a newbie when it comes to LINQ... I have an IEnumerable generic list
Newbie problem: I have a SQL SP with ten parameters (eight input, two output)
I'm a LINQ newbie working on a GIS project involving international postal addresses. One
F# newbie I have 2 XML files in 2 folders c:\root\a\file.xml and c:\root\b\file.xml They
I'm a newbie in Linq and C# and I'm going need some help. These

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.