XML DATA. Writing XML Files
We can
use the XmlWriter class to write XML files. It allows you to write XML text
into a stream and then save it into an xml file.
using
System.Xml; public class Program
{
public
static void Main()
{
XmlWriterSettings
settings = new XmlWriterSettings(); settings.Indent = true;
XmlWriter
writer = XmlWriter.Create("Products.xml", settings);
writer.WriteStartDocument();
writer.WriteComment("This
file is generated by the program.");
writer.WriteStartElement("Product"); writer.WriteAttributeString("ID",
"001"); writer.WriteAttributeString("Name",
"Soap"); writer.WriteElementString("Price",
"10.00"); writer.WriteStartElement("OtherDetails");
writer.WriteElementString("BrandName", "X Soap");
writer.WriteElementString("Manufacturer",
"X Company"); writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
writer.Close();
}
}
Related Topics
Privacy Policy, Terms and Conditions, DMCA Policy and Compliant
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.