XmlTextWriter.WriteString (Método)
Escribe el contenido de texto especificado.

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

Sintaxis

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

instance.WriteString(text)
C#
public override void WriteString (
    string text
)
C++
public:
virtual void WriteString (
    String^ text
) override
J#
public void WriteString (
    String text
)
JScript
public override 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

NotaNota:

En la versión Microsoft .NET Framework versión 2.0, se recomienda crear instancias de XmlWriter mediante el método System.Xml.XmlWriter.Create y la clase XmlWriterSettings. De esta forma, puede aprovechar al máximo todas las nuevas funciones presentadas en esta versión. Para obtener más información, vea Creación de sistemas de escritura XML.

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 fragmento de 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 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
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.
     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();  

  }

}
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.
   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();
}
J#
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
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