You need to do something like this:

// instantiate XmlDocument and load XML from file
XmlDocument doc = new XmlDocument();
doc.Load(@"D:\test.xml");

// get a list of nodes - in this case, I'm selecting all <AID> nodes under
// the <GroupAIDs> node - change to suit your needs
XmlNodeList aNodes = doc.SelectNodes("/Equipment/DataCollections/GroupAIDs/AID");

// loop through all AID nodes
foreach (XmlNode aNode in aNodes)
{
   // grab the "id" attribute
   XmlAttribute idAttribute = aNode.Attributes["id"];

   // check if that attribute even exists...
   if (idAttribute != null)
   {
      // if yes - read its current value
      string currentValue = idAttribute.Value;

      // here, you can now decide what to do - for demo purposes,
      // I just set the ID value to a fixed value if it was empty before
      if (string.IsNullOrEmpty(currentValue))
      {
         idAttribute.Value = "515";
      }
   }
}

// save the XmlDocument back to disk
doc.Save(@"D:\test2.xml");
Answer from marc_s on Stack Overflow
🌐
ROOT
root.cern › doc › master › xmlmodifyfile_8C_source.html
tutorials/xml/xmlmodifyfile.C Source File - CERN Root
creates new attribute for xmlnode, namespaces are not supported for attributes ... store document content to file if layout<=0, no any spaces or newlines will be placed between xmlnode...
🌐
Stack Overflow
stackoverflow.com › questions › 17151392 › modify-xml-file-in-c
Modify XML File in C++ - Stack Overflow
June 17, 2013 - The tree parser holds the whole XML in memory. The stream parser is used for larger XML files. I prefer the tree parser. 2013-06-17T17:18:34.137Z+00:00 ... @TylerJandreau You might want to mention that Codesynthesis XSD needs an XML Schema as input.
🌐
Stack Overflow
stackoverflow.com › questions › 35029549 › how-to-modify-xml-file-and-save-the-changes-using-libxml2-in-c
linux - How to modify xml file and save the changes using libxml2 in C? - Stack Overflow
January 28, 2016 - If you want to modify and write a document, use the "normal" non-streaming API to read a whole document (xmlDoc) into memory (using xmlParseFile, xmlReadFile, etc.), make the required changes, then write the document using xmlDocDump.
🌐
CERN
root.cern.ch › doc › master › xmlmodifyfile_8C_source.html
ROOT: tutorials/xml/xmlmodifyfile.C Source File
creates new attribute for xmlnode, namespaces are not supported for attributes ... store document content to file if layout<=0, no any spaces or newlines will be placed between xmlnode...
🌐
Ncar
ncar.github.io › CESM-Tutorial › notebooks › modifications › xml › model_control_files.html
How to Modify XML Files (*.xml) — CESM Tutorial
We will use xmlchange to modify xml variables and use xmlquery to search xml variables. Note that you can change XML files manually, but using the xmlchange script prevents XML errors and ensures there is a record of your changes in the CaseStatus file.
🌐
Sololearn
sololearn.com › en › Discuss › 3086531 › how-can-i-modify-or-create-an-xml-file-from-c-
How can i modify or create an XML file from C ?? | Sololearn: Learn to code for FREE!
I need to insert some text from my C and GTK code to an XML file, how can i do this?? xmlcgtkglade · 23rd Sep 2022, 4:09 AM · Fidel Alejandro Sanchez Fernandez · 2 Answers · Answer · + 1 · Thanks🙌🏻 · 23rd Sep 2022, 2:42 PM · Fidel Alejandro Sanchez Fernandez ·
Find elsewhere
🌐
Wikihow
wikihow.com › computers and electronics › basic computer skills › how to edit xml files: quickly open, modify, and save
How to Edit XML Files: Quickly Open, Modify, and Save
May 21, 2025 - Open the file you wish to edit by double clicking the file name. The file will open and display the existing code. ... Edit your XML file.
🌐
Rip Tutorial
riptutorial.com › modify xml file
C# Language Tutorial => Modify XML File
Now we extract the FruitColor element out of the Fruit element we just found. Here we assume there is just one, or we only care about the first one. If it is not null, we set the FruitColor to "Brown". Finally, we save the XDocument, overwriting the original file on disk. // 1. string xmlFilePath = "c:\\users\\public\\fruit.xml"; // 2.
🌐
Chron.com
smallbusiness.chron.com › format-xml-files-c-38614.html
How to Format XML Files in C
November 22, 2017 - To create a properly formatted XML file in C, it is important to understand how to write that file. XML files are essentially text files, so a programmer can use the standard file input/output options built into the C programming language.
🌐
Advanced Installer
advancedinstaller.com › user-guide › qa-import-edit-xml-file.html
How to import and edit an XML file
If you wish you could use a predefined dialog from Advanced Installer, for example “SQLConnectionDlg“. After you have added the new dialog in the project, you will have to import your XML file and edit it so it stores the values entered by the user in the edit boxes.
🌐
GitHub
microsoft.github.io › XmlNotepad
XML Notepad
So here we are, a nifty tool that should be useful to those who want a quick way to view and edit XML documents. There have been over 6 million downloads since then - thanks to everyone who tried it out! Ability to load .csv, .json, and .htm files, converting them to XML.
🌐
C# Corner
c-sharpcorner.com › article › xml-manipulation-in-c-sharp
XML Manipulation In C#
June 12, 2023 - This article describes how to add, delete, update, and select nodes in XML in C#. We will use mostly XDocument and XMLDocument class to manipulate XML data.
🌐
Mkyong
mkyong.com › home › java › how to modify xml file in java – (dom parser)
How to modify XML file in Java - (DOM Parser) - Mkyong.com
May 16, 2021 - Later we will use DOM parser to modify the following XML data. ... Remove the XML element name. For the XML element role, update the value to "founder". ... Update the XML attribute to 2222. Add a new XML element salary, contains attribute and value.