Escribe el contenido de texto especificado.
Espacio de nombres: System.Xml
Ensamblado: System.Xml (en system.xml.dll)
Visual Basic (Declaración)
Public Overrides Sub WriteString ( _
text As String _
)
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
)
Parámetros
- text
Texto que se va a escribir.
| Tipo de excepción | Condición |
|---|
ArgumentException | La cadena de texto contiene un par suplente no válido. |
WriteString realiza lo siguiente:
-
Los caracteres &, < y > se reemplazan por &, < y >, 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 � a �x1F).
-
Si se llama a WriteString en el contexto de un valor de atributo, las comillas dobles y simples se reemplazan por " y ', respectivamente.
Por ejemplo, esta cadena de entrada test<item>test se escribe como
Si text es referencia null (Nothing en Visual Basic) o String.Empty, este método escribe un nodo de texto sin contenido de datos.
En el siguiente ejemplo se escribe un fragmento de XML.
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
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.
.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