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