Click here to Skip to main content
15,914,322 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,
i want to add a new node in my existing "XML" file. my xml file structure is like:
<Response>
<Result>SUCCESS</Result>
<Response>
<EmpLoginAPI>
<EmployeeID>214735</EmployeeID>
<OrganizationID>1</OrganizationID>
<CompanyID>81</CompanyID>
<MobileNo>9899912648</MobileNo>
</EmpLoginAPI>
</Response>
</Response>


My expected output is:

<Response>
<Result>SUCCESS</Result>
<Response>
<EmpLoginAPI>
<EmployeeID>214735</EmployeeID>
<OrganizationID>1</OrganizationID>
<CompanyID>81</CompanyID>
<MobileNo>9894672648</MobileNo>
<pre><otp>test</otp>
// this is newly added element







but when i try the given code, i face the error below,
XmlDocument xmlDoc = new XmlDocument();
               xmlDoc.LoadXml(ResXml);
               XmlNode EmpLoginAPI = xmlDoc.SelectSingleNode("//EmpLoginAPI");
               XmlNode MobileNo = xmlDoc.SelectSingleNode("//MobileNo");
               XmlNode xmlRecordNo = xmlDoc.CreateNode(XmlNodeType.Element, "otp", null);
               xmlRecordNo.InnerText = "test";
               EmpLoginAPI.InsertAfter(xmlRecordNo, MobileNo);
               xmlDoc.Save(ResXml);
// here am getting error

error:
Illegal characters in path.



please drop me a solution for this
thanks in advance.

What I have tried:

add a new node in existing xml file
Posted
Updated 15-Mar-17 21:01pm
v2

1 solution

This question was asked and answered in here before: add a new node in existing xml file[^]

It has the information you need to complete your task.
 
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