XmlTextWriter.WriteString(String) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Escreve o texto fornecido.
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)
Parâmetros
- text
- String
Texto para escrever.
Exceções
A cadeia de texto contém um par de substitutos inválido.
Exemplos
O exemplo seguinte escreve um fragmento XML.
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
Observações
Note
Recomendamos que crie instâncias XmlWriter usando o método XmlWriter.Create e a classe XmlWriterSettings para aproveitar a nova funcionalidade.
WriteString faz o seguinte
Os caracteres
&, , e<são substituídos por>,&, e<,>respetivamente.Os valores de caracteres no intervalo 0x-0x1F (excluindo caracteres de espaço em branco 0x9, 0xA e 0xD) são substituídos por entidades numéricas de caracteres (
�até�x1F).Se
WriteStringfor chamado no contexto de um valor de atributo, as aspas duplas e simples são substituídas por"e'respetivamente.
Por exemplo, esta cadeia test<item>test de entrada é escrita como test<item>test.
Se text for ou null , String.Emptyeste método escreve um nó de texto sem conteúdo de dados.