Click here to Skip to main content
15,443,430 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to generate an XML as key-value pair. the file must contain a username and its value, password and its value. Also, I need to read this data. I have tried the following code but not working properly.

The XML file is generating and values are added. but I don't know whether its in proper form. because I cant retrieve data.

What I have tried:

for save the data to xml
using (XmlWriter xmlWriter = XmlWriter.Create(Path.Combine(directory, "sample.xml")))
{

xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("UserData");
xmlWriter.WriteStartElement("UserName");
xmlWriter.WriteAttributeString("value", tbUserName.Text);
xmlWriter.WriteEndElement();
xmlWriter.WriteStartElement("Password");
xmlWriter.WriteAttributeString("value", EncryptPassword);
xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement();
xmlWriter.WriteEndDocument();
}
for reading data
var xmlPath = (Path.Combine(directory, "sample.xml"));
XmlDocument _LocalInfo_Xml = new XmlDocument();
_LocalInfo_Xml.Load(xmlPath);
XmlElement _XmlElement;
_XmlElement = _LocalInfo_Xml.GetElementsByTagName("UserData")[0] as XmlElement;
string Value = _XmlElement.InnerXml;
Posted
Updated 16-Mar-21 21:11pm
Comments
Richard MacCutchan 10-Mar-21 3:56am    
Even with encryption your password data is not secure.

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