hi this structure can be represented in a List of class.
Code:
List<machine> machines = new List<machine>(); // you save/load this to file
class machine{
public string name
public string user2
public string password2
}
if you have the entire xml you can represent it into a class.
after that use xml serialization to save and load that object.
Code:
public static object Load(string path, object destinationType)
{
if (!File.Exists(path))
{
throw new Exception("File not found! " + path);
}
string pXmlString = File.ReadAllText(path);
XmlSerializer serializer = new XmlSerializer(destinationType.GetType());
MemoryStream stream = new MemoryStream(StringToUTF8ByteArray(pXmlString));
return serializer.Deserialize(stream);
}
public static void Save(string filename, object obj)
{
try
{
string fullPath = Path.GetFullPath(filename);
if (!Directory.Exists(Path.GetDirectoryName(fullPath)))
{
Directory.CreateDirectory(Path.GetDirectoryName(fullPath));
}
string str2 = null;
MemoryStream w = new MemoryStream();
XmlSerializer serializer = new XmlSerializer(obj.GetType());
XmlTextWriter writer = new XmlTextWriter(w, Encoding.UTF8);
writer.Formatting = Formatting.None;
serializer.Serialize((XmlWriter) writer, obj);
str2 = UTF8ByteArrayToString(((MemoryStream) writer.BaseStream).ToArray());
File.WriteAllText(fullPath, str2);
}
catch (Exception)
{
throw;
}
}
private static byte[] StringToUTF8ByteArray(string pXmlString)
{
UTF8Encoding encoding = new UTF8Encoding();
return encoding.GetBytes(pXmlString);
}
private static string UTF8ByteArrayToString(byte[] characters)
{
UTF8Encoding encoding = new UTF8Encoding();
return encoding.GetString(characters);
}