XmlTextWriter.WriteString(String) 메서드

정의

주어진 텍스트 콘텐츠를 작성합니다.

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

매개 변수

text
String

작성할 텍스트입니다.

예외

텍스트 문자열에 잘못된 서로게이트 쌍이 포함된 경우

예제

다음 예제에서는 XML 조각을 씁니다.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   
   //Create a writer to write XML to the console.
   XmlTextWriter^ writer = nullptr;
   writer = gcnew XmlTextWriter( Console::Out );
   
   //Use indentation for readability.
   writer->Formatting = Formatting::Indented;
   writer->Indentation = 4;
   
   //Write an element (this one is the root).
   writer->WriteStartElement( "book" );
   
   //Write the title element.
   writer->WriteStartElement( "title" );
   writer->WriteString( "Pride And Prejudice" );
   writer->WriteEndElement();
   
   //Write the close tag for the root 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 a writer to write XML to the console.
     XmlTextWriter writer = null;
     writer = new XmlTextWriter (Console.Out);

     //Use indentation for readability.
     writer.Formatting = Formatting.Indented;
     writer.Indentation = 4;

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

     //Write the title element.
     writer.WriteStartElement("title");
     writer.WriteString("Pride And Prejudice");
     writer.WriteEndElement();

     //Write the close tag for the root element.
     writer.WriteEndElement();

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

Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        'Create a writer to write XML to the console.
        Dim writer As XmlTextWriter = Nothing
        writer = New XmlTextWriter(Console.Out)
        
        'Use indentation for readability.
        writer.Formatting = Formatting.Indented
        writer.Indentation = 4
        
        'Write an element (this one is the root).
        writer.WriteStartElement("book")
        
        'Write the title element.
        writer.WriteStartElement("title")
        writer.WriteString("Pride And Prejudice")
        writer.WriteEndElement()
        
        'Write the close tag for the root 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 것이 좋습니다.

WriteString 은 다음을 수행합니다.

  • 문자&<각각 , >&gt;&amp;``&lt;바뀝니다.

  • 0x-0x1F 범위의 문자 값(공백 문자 0x9, 0xA 및 0xD 제외)은 숫자 문자 엔터티(&#0; ~ &#0x1F)로 바뀝니다.

  • 특성 값의 컨텍스트에서 호출되는 경우 WriteString 큰따옴표와 큰따옴표가 각각과 함께 &quot; &apos; 바뀝니다.

예를 들어 이 입력 문자열 test<item>test 은 .로 test&lt;item&gt;test작성됩니다.

text 또는 이 메서드는 String.Empty``null 데이터 콘텐츠가 없는 텍스트 노드를 씁니다.

적용 대상