XmlDocument.CreateProcessingInstruction(String, String) XmlDocument.CreateProcessingInstruction(String, String) XmlDocument.CreateProcessingInstruction(String, String) XmlDocument.CreateProcessingInstruction(String, String) Method

定義

指定した名前とデータを使用して XmlProcessingInstruction を作成します。Creates an XmlProcessingInstruction with the specified name and data.

public:
 virtual System::Xml::XmlProcessingInstruction ^ CreateProcessingInstruction(System::String ^ target, System::String ^ data);
public virtual System.Xml.XmlProcessingInstruction CreateProcessingInstruction (string target, string data);
abstract member CreateProcessingInstruction : string * string -> System.Xml.XmlProcessingInstruction
override this.CreateProcessingInstruction : string * string -> System.Xml.XmlProcessingInstruction
Public Overridable Function CreateProcessingInstruction (target As String, data As String) As XmlProcessingInstruction

パラメーター

target
String String String String

処理命令の名前。The name of the processing instruction.

data
String String String String

処理命令のデータ。The data for the processing instruction.

戻り値

新しい XmlProcessingInstructionThe new XmlProcessingInstruction.

次の例では、ProcessingInstruction ノードを作成し、ドキュメントに追加します。The following example creates a ProcessingInstruction node and adds it to the document.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlDocument^ doc = gcnew 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 );
}

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

  }
}
Imports System
Imports System.IO
Imports System.Xml

public class Sample

  public shared sub Main()
  
    Dim doc as XmlDocument = new XmlDocument()

    ' Create a procesing instruction.
    Dim newPI as XmlProcessingInstruction 
    Dim PItext as String = "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)

  end sub
end class

注釈

このメソッドでは、新しいオブジェクトを作成し、ドキュメントのコンテキストが自動的に追加しません、新しいオブジェクト、ドキュメント ツリーに。Although this method creates the new object in the context of the document, it does not automatically add the new object to the document tree. 新しいオブジェクトを追加するを明示的に呼び出してノードの挿入方法の 1 つあります。To add the new object, you must explicitly call one of the node insert methods.

W3c Extensible Markup Language (XML) 1.0 勧告、ユーザーが、EntityReference ノードの子でない場合で ProcessingInstruction ノードは、ドキュメント、要素、および EntityReference ノード内でのみ許可します。属性ノード。According to the W3C Extensible Markup Language (XML) 1.0 recommendation, ProcessingInstruction nodes are only allowed within Document, Element, and EntityReference nodes, when the EntityReference node is not a child of an Attribute node.

適用対象