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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:58:16+00:00 2026-05-28T06:58:16+00:00

I Want to add the data to the xml file from my asp.net GUI.So

  • 0

I Want to add the data to the xml file from my asp.net GUI.So i have a textbox in GUI.

So if user enters “IL” then i want to add a section in this way

<Employee Location="IL">
    <Male Value="True" />
    <Name Value="xxx" />
</Employee>

XML file:

 <Emp>
  <Employee Location="NJ">
    <Male Value="True" />
    <Name Value="xxx" />
   </Employee>
  <Employee Location="NY">
    <Male Value="True" />
    <Name Value="xxx" />
   </Employee>
</Emp>

Note:

Every time i add a new section here the inner elements are constant i.e. the following values are always to be same.

<Male Value="True" />
<Name Value="xxx" />

I am looking for how can i achieve this using LINQ to XML?

  • 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-28T06:58:17+00:00Added an answer on May 28, 2026 at 6:58 am

    Since only variable part of node you’re adding is Location attribute, you can very easily extract that process to a method, like the following one:

    private XElement CreateEmployeeNode(string location)
    {
        return new XElement("Employee",
            new XAttribute("Location", location),
            new XElement("Male", new XAttribute("Value", "True")),
            new XElement("Name", new XAttribute("Value", "xxx"))
        );
    }
    

    Now when you want to update your existing XML with new employee data, you do it this way:

    var document = XDocument.Parse(xmlString); // or .Load, depending how you get XML
    var newEmployeeLocation = textBox.Text;
    document.Element("Emp").Add(CreateEmployeeNode(newEmployeeLocation));
    

    New employee node will be added to existing ones.

    For more information on XML trees creation with LINQ to XML (as this is what we’re dealing with here), check online guide here.

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

Sidebar

Related Questions

I have an asp.net web application. The application reads data from an xml. The
I want to add an XML file, containing sensitive data, to my application. I
I have two results from a data set. I want to add both results
I want to add one xml file (which has some static data related to
Possible Duplicate: I want to load the data from XML file and show in
In my application I download some xml data file from some information center, add
I want to add about 150 element from a xml file to a select
I want to add the data-val-required and data-val attributes to an @html.textbox or an
I want to use echo to add data into a text file progressively. I
A few days back I had to de-serialize data from xml file to my

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.