XmlReader.ReadInnerXml (Método)
Cuando se reemplaza en una clase derivada, lee todo el contenido, incluido el marcado, como una cadena.

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

Sintaxis

Visual Basic (Declaración)
Public Overridable Function ReadInnerXml As String
Visual Basic (Uso)
Dim instance As XmlReader
Dim returnValue As String

returnValue = instance.ReadInnerXml
C#
public virtual string ReadInnerXml ()
C++
public:
virtual String^ ReadInnerXml ()
J#
public String ReadInnerXml ()
JScript
public function ReadInnerXml () : String
XAML
No aplicable.

Valor devuelto

Todo el contenido XML, incluido el marcado, del nodo actual. Si el nodo actual no tiene nodos secundarios, se devuelve una cadena vacía. Si el nodo actual no es un elemento ni un atributo, se devuelve una cadena vacía.
Excepciones

Tipo de excepciónCondición

XmlException

El fragmento de XML no está bien formado o se ha producido un error al analizarlo.

Comentarios

Este método devuelve todo el contenido del nodo actual, incluido el marcado. No se devuelven el nodo actual (etiqueta de apertura) ni el correspondiente nodo final (etiqueta de cierre). Por ejemplo, en el siguiente caso:

 <node>
  this <child id="123"/>
 </node>

ReadInnerXml devuelve this <child id="123"/>

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>

text1

En la etiqueta de apertura item2.

Attribute

En el nodo de atributo attr1.

<item attr1="val1" attr2="val2">text</item>

val1

Permanece en el nodo de atributo attr1.

Si el lector está situado en un nodo de hoja, llamar a ReadInnerXml equivale a llamar al método Read. El método devuelve String.Empty (excepto para los nodos de atributos, en cuyo caso se devuelve el valor del atributo).

Este método comprueba si el formato XML es correcto. Si se llama a ReadInnerXml 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.

Ejemplo

En el siguiente ejemplo se comparan los métodos ReadInnerXml y ReadOuterXml.

Visual Basic
' 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
C#
// 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.

None
<!--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>
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