Home | | C Sharp and .NET Framework(CNF) | XML DATA. Writing XML Files

Chapter: C# and .NET Framework

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.

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();

}

}


Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
C# and .NET Framework : XML DATA. Writing XML Files |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.