XmlTextWriter.WriteWhitespace(String) 메서드

정의

주어진 공백을 작성합니다.

public:
 override void WriteWhitespace(System::String ^ ws);
public override void WriteWhitespace (string? ws);
public override void WriteWhitespace (string ws);
override this.WriteWhitespace : string -> unit
Public Overrides Sub WriteWhitespace (ws As String)

매개 변수

ws
String

공백 문자의 문자열입니다.

예외

문자열에 공백이 아닌 문자가 포함된 경우

예제

다음 예제에서는 메서드를 WriteWhitespace 사용하여 파일의 형식을 제어합니다.

#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();
}
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();
  }
}
Option Strict
Option Explicit

Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        ' Create the writer.
        Dim writer As XmlTextWriter = Nothing
        writer = New XmlTextWriter("ws.html", Nothing)
        
        ' Write an element (this one is the root).
        writer.WriteStartElement("p")
        
        ' Write the xml:space attribute.
        writer.WriteAttributeString("xml", "space", Nothing, "preserve")
        
        ' Verify that xml:space is set properly.
        If writer.XmlSpace = XmlSpace.Preserve Then
            Console.WriteLine("xmlspace is correct!")
        End If 
        ' 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()
    End Sub
End Class

설명

참고

.NET Framework 2.0부터는 메서드와 XmlWriterSettings 클래스를 사용하여 XmlWriter.Create 새 기능을 활용하여 인스턴스를 만드는 XmlWriter 것이 좋습니다.

이 메서드는 문서의 서식을 수동으로 지정하는 데 사용됩니다. Formatting 속성을 사용하여 작성기에서 출력의 서식을 자동으로 지정합니다.

적용 대상

추가 정보