Freigeben über


XmlTextWriter.WriteString-Methode

Schreibt den angegebenen Textinhalt.

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

Syntax

'Declaration
Public Overrides Sub WriteString ( _
    text As String _
)
'Usage
Dim instance As XmlTextWriter
Dim text As String

instance.WriteString(text)
public override void WriteString (
    string text
)
public:
virtual void WriteString (
    String^ text
) override
public void WriteString (
    String text
)
public override function WriteString (
    text : String
)

Parameter

  • text
    Zu schreibender Text.

Ausnahmen

Ausnahmetyp Bedingung

ArgumentException

Die Textzeichenfolge enthält ein ungültiges Ersatzzeichenpaar.

Hinweise

Hinweis

Die empfohlene Vorgehensweise für die Version Microsoft .NET Framework, Version 2.0 besteht darin, mithilfe der System.Xml.XmlWriter.Create-Methode und der XmlWriterSettings-Klasse XmlWriter-Instanzen zu erstellen. So können Sie alle neuen Features dieser Version in vollem Umfang nutzen. Weitere Informationen finden Sie unter Erstellen von XML-Writern.

WriteString führt Folgendes aus.

  • Die Zeichen &, < und > werden durch &amp;, &lt; bzw. &gt; ersetzt.

  • Zeichenwerte im Bereich 0x-0x1F (außer den Leerraumzeichen 0x9, 0x10 und 0x13) werden durch numerische Zeichenentitäten (&#0; bis &#0x1F) ersetzt.

  • Wenn WriteString im Kontext eines Attributwerts aufgerufen wird, werden doppelte und einfache Anführungszeichen durch &quot; bzw. &apos; ersetzt.

Die Eingabezeichenfolge test<item>test wird z. B. wie folgt geschrieben.

 test&lt;item&gt;test

Wenn text entweder NULL (Nothing in Visual Basic) oder String.Empty ist, schreibt diese Methode einen Textknoten ohne Dateninhalt.

Beispiel

Im folgenden Beispiel wird ein XML-Fragment geschrieben.

Option Explicit
Option Strict

Imports System
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 'Main 
End Class 'Sample
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();  

  }

}
#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();
}
import System.*;
import System.IO.*;
import System.Xml.*;

public class Sample
{
    public static void main(String[] args)
    {
        //Create a writer to write XML to the console.
        XmlTextWriter writer = null;
        writer = new XmlTextWriter(Console.get_Out());

        //Use indentation for readability.
        writer.set_Formatting(Formatting.Indented);
        writer.set_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();
    } //main 
} //Sample

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

XmlTextWriter-Klasse
XmlTextWriter-Member
System.Xml-Namespace