XmlElement.InnerText プロパティ
ノードとそのすべての子の連結している値を取得または設定します。
Overrides Public Property InnerText As String
[C#]
public override string InnerText {get; set;}
[C++]
public: __property String* get_InnerText();public: __property void set_InnerText(String*);
[JScript]
public override function get InnerText() : String;public override function set InnerText(String);
プロパティ値
ノードとそのすべての子の連結している値。
解説
このプロパティを設定すると、すべての子を指定された文字列の解析済みの内容に置き換えます。
このプロパティは、ドキュメント オブジェクト モデル (DOM: Document Object Model) に対する Microsoft 拡張機能です。
使用例
[Visual Basic, C#, C++] InnerText プロパティと InnerXml プロパティを比較する例を次に示します。
Imports System
Imports System.Xml
public class Test
public shared sub Main()
Dim doc as XmlDocument = new XmlDocument()
doc.LoadXml("<root>"& _
"<elem>some text<child/>more text</elem>" & _
"</root>")
Dim elem as XmlElement
elem = CType (doc.DocumentElement.ChildNodes.Item(0), XmlElement)
' 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 )
end sub
end class
[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>");
XmlElement elem = (XmlElement)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 );
}
}
[C++]
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::Xml;
int main()
{
XmlDocument* doc = new XmlDocument();
doc->LoadXml(S"<root><elem>some text<child/>more text</elem></root>");
XmlElement* elem = dynamic_cast<XmlElement*>(doc->DocumentElement->FirstChild);
// Note that InnerText does not include the markup.
Console::WriteLine(S"Display the InnerText of the element...");
Console::WriteLine(elem->InnerText);
// InnerXml includes the markup of the element.
Console::WriteLine(S"Display the InnerXml of the element...");
Console::WriteLine(elem->InnerXml);
// Set InnerText to a string that includes markup.
// The markup is escaped.
elem->InnerText = S"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 = S"Text containing <markup/>.";
Console::WriteLine(elem->OuterXml);
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET