XmlTextWriter.WriteWhitespace Method (String)

 

Writes out the given white space.

Namespace:   System.Xml
Assembly:  System.Xml (in System.Xml.dll)

public override void WriteWhitespace(
	string ws
)

Parameters

ws
Type: System.String

The string of white space characters.

Exception Condition
ArgumentException

The string contains non-white space characters.

System_CAPS_noteNote

Starting with the .NET Framework 2.0, we recommend that you create XmlWriter instances by using the XmlWriter.Create method and the XmlWriterSettings class to take advantage of new functionality.

This method is used to manually format your document. Use the Formatting property to have the writer format the output automatically.

The following example uses the WriteWhitespace method to control how the file is formatted.

using System;
using System.IO;
using System.Xml;

public class Sample
{  
  public static void Main()
  {
    // Create the writer.
    XmlTextWriter writer = null;
    writer = new XmlTextWriter ("ws.html", null);

    // Write an element (this one is the root).
    writer.WriteStartElement("p");

    // Write the xml:space attribute.
    writer.WriteAttributeString("xml", "space", null, "preserve");

    // Verify that xml:space is set properly.
    if (writer.XmlSpace == XmlSpace.Preserve)
      Console.WriteLine("xmlspace is correct!");

    // Write out the HTML elements.  Insert white space
    // between 'something' and 'Big'
    writer.WriteString("something");
    writer.WriteWhitespace("  ");
    writer.WriteElementString("b", "B");
    writer.WriteString("ig");

    // Write the root end element.
    writer.WriteEndElement();

    // Write the XML to file and close the writer.
    writer.Close();  
  }
}

.NET Framework
Available since 1.1
Return to top
Show: