XmlElement.InnerText 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定節點的串連值和其所有的子節點。
public:
virtual property System::String ^ InnerText { System::String ^ get(); void set(System::String ^ value); };
public override string InnerText { get; set; }
member this.InnerText : string with get, set
Public Overrides Property InnerText As String
屬性值
節點的串連值和其所有的子節點。
範例
下列範例會 InnerText
比較 和 InnerXml 屬性。
#using <System.Xml.dll>
using namespace System;
using namespace System::Xml;
int main()
{
XmlDocument^ doc = gcnew XmlDocument;
doc->LoadXml( "<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( "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 );
}
// This example produces the following results:
//
// 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(>) escaped.</elem>
// <elem>Text containing <markup />.</elem>
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 );
}
}
// This example produces the following results:
//
// 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(>) escaped.</elem>
// <elem>Text containing <markup />.</elem>
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
' This example produces the following results:
'
' 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(>) escaped.</elem>
' <elem>Text containing <markup />.</elem>
備註
設定此屬性會將所有子系取代為指定字串的剖析內容,因此不會保留子節點。 設定作業之後的唯一子節點是文位元組點。
這個屬性是文件物件模型的 Microsoft 擴充功能。