Click here to Skip to main content
15,881,516 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I want to append new node into existing xml file, data that is coming from api of json type independently from model class elements should be append into the file.

What I have tried:

I have tried many ways but not done please give reply
Graeme_Grant 1-Feb-24 0:47am    
Tried many ways? So we can avoid offering a method that you have already tried, please list what methods that you have tried and why they do not work. Use the Improve question link provided above.

XML (and JSON) are Text based data transfer formats: the only practical way to add a new node is to read the XML file into an XMLDocument (or equivalent), add the node to that, and save the XML file again.

You can't just open the "raw" XML as text and write into it: text files of any kind do not have an "insert" function.
Share this answer
While waiting for you to update your question, I used your question in google search: How to append new node in existing XML through api C#[^] and there were many answers to the same question:
* C#, XML, adding new nodes - StackOverflow[^]
* XmlNode.AppendChild(XmlNode) Method (System.Xml) | Microsoft Learn[^] (with sample code)
* add a new node in existing xml file - CodeProject[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900