XmlNode.InnerXml XmlNode.InnerXml XmlNode.InnerXml XmlNode.InnerXml Property

定義

このノードの子ノードだけを表すマークアップを取得または設定します。Gets or sets the markup representing only the child nodes of this node.

public:
 virtual property System::String ^ InnerXml { System::String ^ get(); void set(System::String ^ value); };
public virtual string InnerXml { get; set; }
member this.InnerXml : string with get, set
Public Overridable Property InnerXml As String

プロパティ値

このノードの子ノードのマークアップ。The markup of the child nodes of this node.

InnerXml は既定の属性を返しません。InnerXml does not return default attributes.

例外

子ノードを持つことができないノードでこのプロパティを設定します。Setting this property on a node that cannot have child nodes.

このプロパティの設定時に指定される XML は、整形式ではありません。The XML specified when setting this property is not well-formed.

次の例では、比較、InnerTextInnerXmlプロパティ。The following example compares the InnerText and InnerXml properties.

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

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 );
  }
}
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 XmlNode = 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 )
    
  end sub
end class

注釈

子ノードを持つことができないノードからこのプロパティを設定しようとすると、たとえばテキスト ノードでは、例外をスローします。Attempting to set this property from a node that cannot have child nodes, for example a Text node, throws an exception. それ以外の場合、設定InnerXmlノードの子ノードを指定した文字列の解析された内容に置き換えます。Otherwise, setting InnerXml replaces the child nodes, of the node, with the parsed contents of the given string. 文字列の解析は、現在の名前空間コンテキストで実行されます。The parsing is done in the current namespace context.

このプロパティは、ドキュメント オブジェクト モデル (DOM) の Microsoft 拡張機能です。This property is a Microsoft extension to the Document Object Model (DOM).

注意

InnerXml DOM を変更する効率的な方法ではありません。InnerXml is not an efficient way to modify the DOM. 複雑なノードを置き換えることのパフォーマンスの問題があります。There may be performance issues when replacing complex nodes. ノードを作成してなどのメソッドを使用する方が効率的ですInsertBeforeInsertAfterAppendChild、およびRemoveChildXml ドキュメントを変更します。It is more efficient to construct nodes and use methods such as InsertBefore, InsertAfter, AppendChild, and RemoveChild to modify the Xml document.

適用対象