XmlDocument.CreateProcessingInstruction(String, String) Metoda

Definice

Vytvoří se zadaným XmlProcessingInstruction názvem a daty.

public:
 virtual System::Xml::XmlProcessingInstruction ^ CreateProcessingInstruction(System::String ^ target, System::String ^ data);
public virtual System.Xml.XmlProcessingInstruction CreateProcessingInstruction(string target, 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

Parametry

target
String

Název instrukce pro zpracování.

data
String

Data pro pokyny ke zpracování.

Návraty

XmlProcessingInstructionNový .

Příklady

Následující příklad vytvoří uzel ProcessingInstruction a přidá ho do dokumentu.

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

Poznámky

I když tato metoda vytvoří nový objekt v kontextu dokumentu, nepřidá automaticky nový objekt do stromu dokumentu. Chcete-li přidat nový objekt, musíte explicitně volat jednu z metod vložení uzlu.

Podle doporučení W3C Extensible Markup Language (XML) 1.0 jsou uzly ProcessingInstruction povoleny pouze v uzlech Document, Element a EntityReference, pokud uzel EntityReference není podřízeným uzlem atributu.

Platí pro