Illustrates the XmlTextWriter class : XML Write « XML « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » XML » XML WriteScreenshots 
Illustrates the XmlTextWriter class

/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy

Publisher: Sybex;
ISBN: 0782129110
*/


/*
  Example20_1.cs illustrates the XmlTextWriter class
*/

using System;
using System.Xml;

public class Example20_1 
{

    public static void Main() 
    {

        // use the XmlTextWriter to open a new XML file
        XmlTextWriter xw = new XmlTextWriter(@"Cust4.xml"
            System.Text.Encoding.UTF8);

        // write the document declaration
        xw.WriteStartDocument();

        // write the first element
        xw.WriteStartElement("NewDataSet");

        // write the first customer
        xw.WriteStartElement("Customers");
        xw.WriteElementString("CustomerID""ALFKI");
        xw.WriteElementString("CompanyName""Alfreds Futterkiste");
        xw.WriteElementString("ContactName""Maria Anders");
        xw.WriteElementString("ContactTitle""Sales Representative");
        xw.WriteElementString("Address""Obere Str. 57");
        xw.WriteElementString("City""Berlin");
        xw.WriteElementString("PostalCode""12209");
        xw.WriteElementString("Country""Germany");
        xw.WriteElementString("Phone""030-0074321");
        xw.WriteElementString("Fax""030-0076545");
        xw.WriteEndElement();

        // write the second customer
        xw.WriteStartElement("Customers");
        xw.WriteElementString("CustomerID""BONAPP");
        xw.WriteElementString("CompanyName""Bon App'");
        xw.WriteElementString("ContactName""Laurence Lebihan");
        xw.WriteElementString("ContactTitle""Owner");
        xw.WriteElementString("Address""12, rue des Bouchers");
        xw.WriteElementString("City""Marseille");
        xw.WriteElementString("PostalCode""13008");
        xw.WriteElementString("Country""France");
        xw.WriteElementString("Phone""91.24.45.40");
        xw.WriteElementString("Fax""91.24.45.41");
        xw.WriteEndElement();

        // end the NewDataSet element
        xw.WriteEndElement();

        // end the document
        xw.WriteEndDocument();

        // flush and close
        xw.Flush();
        xw.Close();
    }

}

/**/

           
       
Related examples in the same category
1.Create XML document with XmlWriter
2.Read and Write XML Without Loading an Entire Document into MemoryRead and Write XML Without Loading an Entire Document into Memory
3.Writing XML with the XmlWriter ClassWriting XML with the XmlWriter Class
4.Write To XML File
5.Write XML document to console
6.XML Write: comment, start element, end element, attribute
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.