XmlWriter.WriteString(String) 메서드

정의

파생 클래스에서 재정의되면 지정된 텍스트 콘텐츠를 작성합니다.

public:
 abstract void WriteString(System::String ^ text);
public abstract void WriteString (string text);
public abstract void WriteString (string? text);
abstract member WriteString : string -> unit
Public MustOverride Sub WriteString (text As String)

매개 변수

text
String

쓸 텍스트입니다.

예외

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

이전 비동기 작업이 완료되기 전에 XmlWriter 메서드가 호출되었습니다. 이 경우 “비동기 작업이 이미 진행 중입니다.” 메시지를 나타내며 InvalidOperationException이 throw됩니다.

예제

다음 예제에서는 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.
   XmlWriterSettings^ settings = gcnew XmlWriterSettings;
   settings->Indent = true;
   settings->OmitXmlDeclaration = true;
   XmlWriter^ writer = XmlWriter::Create( Console::Out, settings );
   
   // Write the book element.
   writer->WriteStartElement( L"book" );
   
   // Write the title element.
   writer->WriteStartElement( L"title" );
   writer->WriteString( L"Pride And Prejudice" );
   writer->WriteEndElement();
   
   // Write the close tag for the root element.
   writer->WriteEndElement();
   
   // Write the XML and close the writer.
   writer->Close();
   return 1;
}
using System;
using System.IO;
using System.Xml;

public class Sample {

  public static void Main() {

     // Create a writer to write XML to the console.
     XmlWriterSettings settings = new XmlWriterSettings();
     settings.Indent = true;
     settings.OmitXmlDeclaration = true;
     XmlWriter writer = XmlWriter.Create(Console.Out, settings);

     // Write the book element.
     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 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 settings As XmlWriterSettings = new XmlWriterSettings()
     settings.Indent = true
     settings.OmitXmlDeclaration = true
     Dim writer As XmlWriter = XmlWriter.Create(Console.Out, settings)

     ' Write the book element.
     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 and close the writer.
     writer.Close()

  End Sub
End Class

설명

WriteString은 다음을 수행합니다.

  • , 및 ><문자&는 각각 , &lt;&gt;&amp;대체됩니다.

  • 를 사용하여 Create 만든 의 XmlWriter 기본 동작은 0x-0x1F 범위에서 문자 값을 쓰려고 할 때 를 throw ArgumentException 하는 것입니다(공백 문자 0x9, 0xA 및 0xD 제외). 속성이 로 설정된 를 XmlWriterCheckCharacters 만들어 이러한 잘못된 XML 문자를 작성할 false수 있습니다. 이렇게 하면 문자가 숫자 문자 엔터티(�x1F를 통해 �)로 바뀝니다. 또한 연산자로 XmlTextWriter 만든 new 는 잘못된 문자를 기본적으로 숫자 문자 엔터티로 바꿉니다.

참고 Microsoft 실제로 많은 애플리케이션 XML을 사용 하는 잘못 된 문자를 처리 하도록 설계 되지 하므로 잘못 된 XML 문자를 작성 하는 것을 권장 하지 않습니다.

  • 특성 값의 컨텍스트에서 가 호출되면 WriteString 큰따옴표와 작은따옴표가 각각 및 &apos;&quot; 바뀝니다.

예를 들어 이 입력 문자열 test<item>test 은 다음과 같이 기록됩니다.

test<item>test

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

이 메서드의 비동기 버전은 를 참조하세요 WriteStringAsync.

적용 대상