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.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
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
7.Create XmlWriter using the static XmlWriter.Create method.
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.