XmlWriter.WriteString (Método)
Cuando se reemplaza en una clase derivada, escribe el contenido de texto especificado.

Espacio de nombres: System.Xml
Ensamblado: System.Xml (en system.xml.dll)

Sintaxis

Visual Basic (Declaración)
Public MustOverride Sub WriteString ( _
    text As String _
)
Visual Basic (Uso)
Dim instance As XmlWriter
Dim text As String

instance.WriteString(text)
C#
public abstract void WriteString (
    string text
)
C++
public:
virtual void WriteString (
    String^ text
) abstract
J#
public abstract void WriteString (
    String text
)
JScript
public abstract function WriteString (
    text : String
)
XAML
No aplicable.

Parámetros

text

Texto que se va a escribir.

Excepciones

Tipo de excepciónCondición

ArgumentException

La cadena de texto contiene un par suplente no válido.

Comentarios

WriteString realiza lo siguiente:

  • Los caracteres &, < y > se reemplazan por &amp;, &lt; y &gt;, respectivamente.

  • Los valores de carácter comprendidos en el intervalo de 0x a 0x1F (excluidos los caracteres de espacio en blanco 0x9, 0xA y 0xD) se reemplazan por entidades de caracteres numéricos (de &#0; a &#0x1F).

  • Si se llama a WriteString en el contexto de un valor de atributo, las comillas dobles y simples se reemplazan por &quot; y &apos;, respectivamente.

Por ejemplo, esta cadena de entrada test<item>test se escribe como

 test&lt;item&gt;test

Si text es referencia null (Nothing en Visual Basic) o String.Empty, este método escribe un nodo de texto sin contenido de datos.

Ejemplo

En el siguiente ejemplo, se escribe un nodo XML.

Visual Basic
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 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 'Main 
End Class 'Sample
C#
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();  

  }
}
C++
#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;
}
Plataformas

Windows 98, Windows 2000 Service Pack 4, Windows CE, Windows Millennium, Windows Mobile para Pocket PC, Windows Mobile para Smartphone, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter

Microsoft .NET Framework 3.0 es compatible con Windows Vista, Microsoft Windows XP SP2 y Windows Server 2003 SP1.

Información de versión

.NET Framework

Compatible con: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Compatible con: 2.0, 1.0

XNA Framework

Compatible con: 1.0
Vea también

Page view tracker