I am trying to save some values ββin an xml file. I have already created an Xml file and am trying to overwrite the data. Code is provided ..
/ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml; public class StorePassword { public StorePassword() { } public void store(NewPassword nps) { XmlDocument XmlDoc = new XmlDocument();
at the touch of a button.
NewPassword nps = new NewPassword(); nps.username = TxtUser.Text; nps.Password = TxtNewPassword.Text; StorePassword sp=new StorePassword(); sp.store(nps);
An existing Xml file contains the following.
<?xml version="1.0" encoding="utf-8"?> <ROOT> <UserName>abc</UserName> <PassWord>123</PassWord> </ROOT>
But it does not work.
Data at the root level is invalid. Line 1, Position 1
this error occurs.
Changed the code as XmlDoc.Load(@"Password.xml");
now the error has changed to
Root element is missing. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Xml.XmlException: Root element is missing.
Why is this happening?
source share