XmlNode.InnerText Propiedad

Definición

Obtiene o establece los valores concatenados del nodo y de todos sus nodos secundarios.

C#
public virtual string InnerText { get; set; }

Valor de propiedad

String

Valores concatenados del nodo y de todos sus nodos secundarios.

Ejemplos

En el ejemplo siguiente se comparan las InnerText propiedades y InnerXml .

C#
using System;
using System.Xml;
public class Test {

  public static void Main() {
    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<root>"+
                "<elem>some text<child/>more text</elem>" +
                "</root>");

    XmlNode elem = doc.DocumentElement.FirstChild;

    // Note that InnerText does not include the markup.
    Console.WriteLine("Display the InnerText of the element...");
    Console.WriteLine( elem.InnerText );

    // InnerXml includes the markup of the element.
    Console.WriteLine("Display the InnerXml of the element...");
    Console.WriteLine(elem.InnerXml);

    // Set InnerText to a string that includes markup.
    // The markup is escaped.
    elem.InnerText = "Text containing <markup/> will have char(<) and char(>) escaped.";
    Console.WriteLine( elem.OuterXml );

    // Set InnerXml to a string that includes markup.
    // The markup is not escaped.
    elem.InnerXml = "Text containing <markup/>.";
    Console.WriteLine( elem.OuterXml );
  }
}

Salida:

Display the InnerText of the element...  
some textmore text  
Display the InnerXml of the element...  
some text<child />more text  
<elem>Text containing <markup/> will have char(<) and char(>) escape  
d.</elem>  
<elem>Text containing <markup />.</elem>  

Comentarios

Al establecer esta propiedad, se reemplazan todos los nodos secundarios por el contenido analizado de la cadena especificada.

En el caso de los nodos hoja, InnerText devuelve el mismo contenido que la Value propiedad .

Esta propiedad es una extensión de Microsoft para Document Object Model (DOM).

Se aplica a

Producto Versiones
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 2.0, 2.1
UWP 10.0