英語で読む

次の方法で共有


XmlDocument.CreateProcessingInstruction(String, String) メソッド

定義

指定した名前とデータを使用して XmlProcessingInstruction を作成します。

C#
public virtual System.Xml.XmlProcessingInstruction CreateProcessingInstruction(string target, string data);
C#
public virtual System.Xml.XmlProcessingInstruction CreateProcessingInstruction(string target, string? data);

パラメーター

target
String

処理命令の名前。

data
String

処理命令のデータ。

戻り値

新しい XmlProcessingInstruction

次の例では、ProcessingInstruction ノードを作成し、ドキュメントに追加します。

C#
using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main()
  {
    XmlDocument doc = new XmlDocument();

    // Create a procesing instruction.
    XmlProcessingInstruction newPI;
    String PItext = "type='text/xsl' href='book.xsl'";
    newPI = doc.CreateProcessingInstruction("xml-stylesheet", PItext);

    // Display the target and data information.
    Console.WriteLine("<?{0} {1}?>", newPI.Target, newPI.Data);

    // Add the processing instruction node to the document.
    doc.AppendChild(newPI);
  }
}

注釈

このメソッドはドキュメントのコンテキストで新しいオブジェクトを作成しますが、ドキュメント ツリーに新しいオブジェクトを自動的に追加することはありません。 新しいオブジェクトを追加するには、ノード挿入メソッドのいずれかを明示的に呼び出す必要があります。

W3C 拡張マークアップ言語 (XML) 1.0 の推奨事項によると、ProcessingInstruction ノードは、EntityReference ノードが Attribute ノードの子でない場合、Document、Element、および EntityReference ノード内でのみ許可されます。

適用対象

製品 バージョン
.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, 8, 9, 10
.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, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0