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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:01:57+00:00 2026-06-07T02:01:57+00:00

I have an XML file. I want to update (add some nodes) to it.

  • 0

I have an XML file.
I want to update (add some nodes) to it.
Here is how the code looks:

var xmlDocuments = XDocument.Load(filePath);
var documentElementToEdit = xmlDocuments.Element("Container").Element("Documents").Elements("Document").Where(x => x.Element("GUID").Value == GUID).FirstOrDefault();
missingIndexData1 = new XElement("IndexData");
XElement indexData1 = new XElement("Name", "somename");
XElement indexData2 = new XElement("Value", somevalue);
XElement indexData3 = new XElement("DataType", "3");
XElement indexData4 = new XElement("CreationTime", DateTime.Now.ToString("O"));
XElement indexData5 = new XElement("CreationTimeUTC", DateTime.UtcNow.ToString("O"));
missingIndexData1.Add(indexData1);
missingIndexData1.Add(indexData2);
missingIndexData1.Add(indexData3);
missingIndexData1.Add(indexData4);
missingIndexData1.Add(indexData5);
documentElementToEdit.Element("IndexDatas").Add(missingIndexData1);
documentElementToEdit.Save(filePath);

What this does is that it overwrittes the original XML file with only this document node.
How can I update the document node in the original file?

  • 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-06-07T02:01:59+00:00Added an answer on June 7, 2026 at 2:01 am

    What this does is that it overwrittes the original XML file with only this document node. How can I update the document node in the original file?

    You need to save the whole document, instead of just the changed element. That will rewrite the whole file, of course, but there’s no simple way round that.

    xmlDocuments.Save(filePath);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a xml file with following entries, I want to update. I have
I have an XML file containing some scientific text that I want to display
I have an xml file that I want to configure using a bash script.
I have an XML file (on the left) and I want to create multiple
I have an xml data file and I want to populate a listview in
I have a simple xml file and I want to remove everything before the
I have a single XML file that I want to index using Lucene.NET. The
I have thread where downloading xml file a this xml file i want to
I have an XML file and parse it into my PHP document. I want
I have an xml file I need to modify: ... </web-app> I want to

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.