Cuando se reemplaza en una clase derivada, lee el contenido, incluido el marcado, que representa este nodo y todos sus nodos secundarios.
Espacio de nombres: System.Xml
Ensamblado: System.Xml (en system.xml.dll)
Visual Basic (Declaración)
Public Overridable Function ReadOuterXml As String
Dim instance As XmlReader
Dim returnValue As String
returnValue = instance.ReadOuterXml
public virtual string ReadOuterXml ()
public:
virtual String^ ReadOuterXml ()
public String ReadOuterXml ()
public function ReadOuterXml () : String
Valor devuelto
Si el lector está situado en un nodo de elemento o de atributo, este método devuelve todo el contenido XML, incluido el marcado, del nodo actual y de todos sus nodos secundarios; en caso contrario, devuelve una cadena vacía.
| Tipo de excepción | Condición |
|---|
XmlException | El fragmento de XML no está bien formado o se ha producido un error al analizarlo. |
Este método es similar al método ReadInnerXml, salvo que también devuelve las etiquetas de apertura y de cierre.
Este método controla los nodos de elemento y de atributo de la siguiente manera:
| Tipo de nodo | Posición antes de la llamada | Fragmento XML | Valor devuelto | Posición después de la llamada |
| Element | En la etiqueta de apertura item1. | <item1>text1</item1><item2>text2</item2> | <item1>text1</item1> | En la etiqueta de apertura item2. |
| Attribute | En el nodo de atributo attr1. | <item attr1="val1" attr2="val2">text</item> | attr1="val1" | Permanece en el nodo de atributo attr1. |
Si el lector está situado en un nodo de hoja, llamar a ReadOuterXml equivale a llamar al método Read. El método devuelve String.Empty (excepto en los nodos de atributo, en cuyo caso se devuelve el marcado de atributo).
Este método comprueba si el formato XML es correcto. Si se llama a ReadOuterXml desde XmlValidatingReader, este método valida también el contenido devuelto.
Implementado en las clases XmlNodeReader, XmlTextReader y XmlValidatingReader el método ReadOuterXml reconoce el espacio de nombres. Dado el siguiente texto XML <A xmlns:S="urn:1"><S:B>hello</S:B></A>, si el lector se coloca en la etiqueta de apertura S:B, ReadOuterXml devuelve <S:B xmlns:S="urn:1">hello<S:B/>.
En el siguiente ejemplo se comparan los métodos ReadInnerXml y ReadOuterXml.
' Load the file and ignore all white space.
Dim settings As New XmlReaderSettings()
settings.IgnoreWhitespace = True
Using reader As XmlReader = XmlReader.Create("2books.xml")
' Moves the reader to the root element.
reader.MoveToContent()
' Moves to book node.
reader.Read()
' Note that ReadInnerXml only returns the markup of the node's children
' so the book's attributes are not returned.
Console.WriteLine("Read the first book using ReadInnerXml...")
Console.WriteLine(reader.ReadInnerXml())
' ReadOuterXml returns the markup for the current node and its children
' so the book's attributes are also returned.
Console.WriteLine("Read the second book using ReadOuterXml...")
Console.WriteLine(reader.ReadOuterXml())
End Using
// Load the file and ignore all white space.
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreWhitespace = true;
using (XmlReader reader = XmlReader.Create("2books.xml")) {
// Moves the reader to the root element.
reader.MoveToContent();
// Moves to book node.
reader.Read();
// Note that ReadInnerXml only returns the markup of the node's children
// so the book's attributes are not returned.
Console.WriteLine("Read the first book using ReadInnerXml...");
Console.WriteLine(reader.ReadInnerXml());
// ReadOuterXml returns the markup for the current node and its children
// so the book's attributes are also returned.
Console.WriteLine("Read the second book using ReadOuterXml...");
Console.WriteLine(reader.ReadOuterXml());
}
En el ejemplo se utiliza el archivo 2books.xml como entrada.
<!--sample XML fragment-->
<bookstore>
<book genre='novel' ISBN='10-861003-324'>
<title>The Handmaid's Tale</title>
<price>19.95</price>
</book>
<book genre='novel' ISBN='1-861001-57-5'>
<title>Pride And Prejudice</title>
<price>24.95</price>
</book>
</bookstore>
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