Writing to XML
XmlTextWriter writer = new XmlTextWriter("C:/TEMP/product.xml", System.Text.Encoding.UTF8);
writer.WriteStartDocument(true);
writer.Formatting = Formatting.Indented;
writer.Indentation = 2;
writer.WriteStartElement("Properties");
createNode("model", "modelS", writer);
createNode("supplier", "x", writer);
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();
Helper Method
private static void createNode(string key, string value, XmlTextWriter writer)
{
writer.WriteStartElement(key);
writer.WriteString(value);
writer.WriteEndElement();
}
Reading XML
XmlDataDocument xmldoc = new XmlDataDocument();
XmlNodeList xmlnode;
int i = 0;
string str = null;
FileStream fs = new FileStream("C:/TEMP/product.xml", FileMode.Open, FileAccess.Read);
xmldoc.Load(fs);
xmlnode = xmldoc.GetElementsByTagName("Properties")[0].ChildNodes;
for (i = 0; i <= xmlnode.Count - 1; i++)
{
str = xmlnode[i].Name +" | "+xmlnode[i].ChildNodes.Item(0).InnerText.Trim();
Console.WriteLine(str);
}
XML Pattern