XmlTextWriter.WriteString(String) Metoda

Definice

Zapíše daný textový obsah.

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)

Parametry

text
String

Text k zápisu

Výjimky

Textový řetězec obsahuje neplatný náhradní pár.

Příklady

Následující příklad zapíše fragment 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

Poznámky

Poznámka

Počínaje verzí .NET Framework 2.0 doporučujeme vytvářet XmlWriter instance pomocí XmlWriter.Create metody a XmlWriterSettings třídy, abyste mohli využívat nové funkce.

WriteString provede následující:

  • Znaky &, <a > jsou nahrazeny znakem &amp;, &lt;a &gt;, v uvedeném pořadí.

  • Hodnoty znaků v rozsahu 0x-0x1F (s výjimkou prázdných znaků 0x9, 0xA a 0xD) se nahradí číselnými entitami znaků (&#0;&#0x1F).

  • Pokud WriteString je volána v kontextu hodnoty atributu, dvojité a jednoduché uvozovky jsou nahrazeny &quot; a &apos; v uvedeném pořadí.

Například tento vstupní řetězec test<item>test je zapsán jako test&lt;item&gt;test.

Pokud text je nebo null String.Empty, tato metoda zapíše textový uzel bez datového obsahu.

Platí pro