Type Summary



Type Summary


public enum Formatting

    {

    Indented = 1,

    None = 0,

    }


JM Back on February 28, 2001, when the first edition of the CLI specification was being standardized, there was a meeting in Redmond, Washington, amongst the co-sponsors of the standardization process (Microsoft, Intel, Hewlett-Packard). During this meeting we were slated to do a pre-review of the XML, Networking, and Reflection classes. Well, for those of you who were in the Seattle area that day, I don't have to remind you of the 6.8 earthquake that occurred at around 10:54 AM (and 32 seconds). We were on a break and everyone except for Brad, myself, and an HP representative had left the meeting room. Luckily for Brad and me, the HP representative was on top of things because, as Brad and I were looking like deer in the headlights, listening to the walls creak, she said we should get under the table (as any basic earthquake drill will tell you). And, hence, we got under the table and came out unscathed. I wish I had a picture of the three of us huddled under there.


Example

using System;

using System.Xml;





/// <summary>

/// This sample shows writing a simple Xml document to the console with no

/// formatting and with Indented formatting

/// </summary>

public class FormattingSample

{

    public static void Main()

    {

        WriteSomeElements(Formatting.None);

        WriteSomeElements(Formatting.Indented);

        Console.WriteLine();

        Console.WriteLine();

        Console.WriteLine("Press Enter to continue");

        Console.ReadLine();

    }



    static void WriteSomeElements(Formatting wformat)

    {

        Console.WriteLine();

        Console.WriteLine();

        Console.WriteLine("With Formatting {0}:", wformat);

        XmlTextWriter w = new XmlTextWriter(Console.Out);

        w.Formatting = wformat;

        w.WriteStartDocument();

        w.WriteStartElement("root");

        w.WriteElementString("subelement", "sample");

        w.WriteEndElement();

        w.WriteEndDocument();

        w.Close();

    }



}




The output is


With Formatting None:

<?xml version="1.0" encoding="IBM437"?><root><subelement>sample</subelement></ro

ot>



With Formatting Indented:

<?xml version="1.0" encoding="IBM437"?>

<root>

  <subelement>sample</subelement>

</root>



Press Enter to continue