XmlWriter

In this chapter you will learn:

  1. How to create xml file with XmlWriter

Create XML file

using System;// j  av a2 s  .  com
using System.Data;
using System.Text;
using System.Xml;

public class MainClass
{
    public static void Main()
    {
        XmlWriter writer;
        writer = XmlWriter.Create("output.xml");
        writer.WriteStartDocument();
        writer.WriteStartElement("pubs");
        writer.WriteStartElement("titles");
        writer.WriteStartAttribute("name");
        writer.WriteValue("value");
        writer.WriteEndAttribute();
        writer.WriteStartAttribute("price");
        writer.WriteValue(19.99);
        writer.WriteEndAttribute();
        writer.WriteEndElement();
        writer.WriteEndElement();
        writer.Close();
    }
}

Next chapter...

What you will learn in the next chapter:

  1. How to use XmlWriterSettings to control the outpit
Home » C# Tutorial » XML
Parse XML file
Parse XML String
Parse XML from URL
Element create
Attribute create
Comments create
XProcessingInstruction
XmlReader
Read double value from XML
XmlReader
XmlReaderSettings
XML formatter
XmlSerializer
XmlTextReader
XmlTextWriter
XmlWriter
XmlWriterSettings
Output XML to console