Share via


XmlDocument.CreateProcessingInstruction(String, String) 메서드

정의

지정된 이름과 데이터가 있는 XmlProcessingInstruction을 만듭니다.

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

처리 명령의 이름입니다.

data
String

처리 명령의 데이터입니다.

반환

XmlProcessingInstruction

XmlProcessingInstruction입니다.

예제

다음 예제에서는 ProcessingInstruction 노드를 만들고 문서에 추가합니다.

#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.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

설명

이 메서드는 문서의 컨텍스트에서 새 개체를 만들지만 문서 트리에 새 개체를 자동으로 추가하지는 않습니다. 새 개체를 추가하려면 노드 삽입 메서드 중 하나를 명시적으로 호출해야 합니다.

W3C XML(Extensible Markup Language) 1.0 권장 사항에 따라 ProcessingInstruction 노드는 EntityReference 노드가 특성 노드의 자식이 아닌 경우 Document, Element 및 EntityReference 노드 내에서만 허용됩니다.

적용 대상