Прочитать на английском

Поделиться через


XmlNode.InnerText Свойство

Определение

Возвращает или задает связанные значения узла и всех его дочерних узлов.

public virtual string InnerText { get; set; }

Значение свойства

String

Связанные значения узла и всех его дочерних узлов.

Примеры

В следующем примере сравниваются InnerText свойства и InnerXml свойства.

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 );
  }
}

Выходные данные:

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>  

Комментарии

Если задать это свойство, все дочерние узлы заменяются проанализированным содержимым заданной строки.

Для конечных узлов возвращает то же содержимое, InnerText что и Value свойство.

Это свойство является расширением Microsoft для объектной модели документа (DOM).

Применяется к

Продукт Версии
.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