XmlTextWriter::WriteWhitespace Method (String^)

 

Writes out the given white space.

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

public:
virtual void WriteWhitespace(
	String^ ws
) override

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.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{

   // Create the writer.
   XmlTextWriter^ writer = nullptr;
   writer = gcnew XmlTextWriter( "ws.html", nullptr );

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

   // Write the xml:space attribute.
   writer->WriteAttributeString( "xml", "space", nullptr, "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: