using System.Xml;
private void WriteXML()
{
XmlTextWriter writer = null;
writer = new XmlTextWriter("E://MyXML.Xml",null);
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
writer.WriteStartElement("Connection");
writer.WriteStartElement("DataBase");
writer.WriteString("myDataBase");
writer.WriteEndElement();
writer.WriteStartElement("PassWord");
writer.WriteString("myPassWord");
writer.WriteEndElement();
writer.WriteStartElement("UserID");
writer.WriteString("MyUserID");
writer.WriteEndElement();
writer.WriteStartElement("Server");
writer.WriteString("myServer");
writer.WriteEndElement();
writer.WriteEndElement();
writer.Close();
}
private void ReadXML()
{
string DataBase = "";
string PassWord = "";
string UserID = "";
string Server = "";
XmlTextReader reader;
reader = new XmlTextReader("E://myXML.Xml");
while(reader.Read())
{
if ((reader.NodeType == XmlNodeType.EndElement) && (reader.Name == "Connection"))
{
break;
}
if (reader.IsStartElement("DataBase"))
{
reader.Read();
DataBase = reader.Value;
}
if (reader.IsStartElement("PassWord"))
{
reader.Read();
PassWord = reader.Value;
}
if (reader.IsStartElement("UserID"))
{
reader.Read();
UserID = reader.Value;
}
if (reader.IsStartElement("Server"))
{
reader.Read();
Server = reader.Value;
}
}
}
private void WriteXML()
{
XmlTextWriter writer = null;
writer = new XmlTextWriter("E://MyXML.Xml",null);
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
writer.WriteStartElement("Connection");
writer.WriteStartElement("DataBase");
writer.WriteString("myDataBase");
writer.WriteEndElement();
writer.WriteStartElement("PassWord");
writer.WriteString("myPassWord");
writer.WriteEndElement();
writer.WriteStartElement("UserID");
writer.WriteString("MyUserID");
writer.WriteEndElement();
writer.WriteStartElement("Server");
writer.WriteString("myServer");
writer.WriteEndElement();
writer.WriteEndElement();
writer.Close();
}
private void ReadXML()
{
string DataBase = "";
string PassWord = "";
string UserID = "";
string Server = "";
XmlTextReader reader;
reader = new XmlTextReader("E://myXML.Xml");
while(reader.Read())
{
if ((reader.NodeType == XmlNodeType.EndElement) && (reader.Name == "Connection"))
{
break;
}
if (reader.IsStartElement("DataBase"))
{
reader.Read();
DataBase = reader.Value;
}
if (reader.IsStartElement("PassWord"))
{
reader.Read();
PassWord = reader.Value;
}
if (reader.IsStartElement("UserID"))
{
reader.Read();
UserID = reader.Value;
}
if (reader.IsStartElement("Server"))
{
reader.Read();
Server = reader.Value;
}
}
}