XmlDocument..::.CreateProcessingInstruction

.NET Framework 类库
XmlDocument . . :: .CreateProcessingInstruction 方法

更新:2007 年 11 月

创建一个具有指定名称和数据的 XmlProcessingInstruction

命名空间:   System.Xml
程序集:   System.Xml(在 System.Xml.dll 中)
Visual Basic(声明)
Public Overridable Function CreateProcessingInstruction ( _
    target As String, _
    data As String _
) As XmlProcessingInstruction
Visual Basic (用法)
Dim instance As XmlDocument
Dim target As String
Dim data As String
Dim returnValue As XmlProcessingInstruction

returnValue = instance.CreateProcessingInstruction(target, _
    data)
C#
public virtual XmlProcessingInstruction CreateProcessingInstruction(
    string target,
    string data
)
Visual C++
public:
virtual XmlProcessingInstruction^ CreateProcessingInstruction(
    String^ target, 
    String^ data
)
J#
public XmlProcessingInstruction CreateProcessingInstruction(
    String target,
    String data
)
JScript
public function CreateProcessingInstruction(
    target : String, 
    data : String
) : XmlProcessingInstruction

参数

target
类型: System..::.String
处理指令的名称。
data
类型: System..::.String
处理指令的数据。

返回值

类型: System.Xml..::.XmlProcessingInstruction
新的 XmlProcessingInstruction

尽管此方法在文档的上下文中创建新对象,但它并不自动将新对象添加到文档树。若要添加新对象,必须显式调用节点插入方法之一。

根据 W3C 可扩展标记语言 (XML) 1.0 建议 (www.w3.org/TR/1998/REC-xml-19980210),ProcessingInstruction 节点可包含在 Document 节点和 Element 节点中,并且当 EntityReference 节点不是 Attribute 节点的子级时,ProcessingInstruction 节点还可包含在 EntityReference 节点中。

下面的示例创建一个 ProcessingInstruction 节点并将其添加到文档中。

Visual Basic
复制代码
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

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

  }
}

Visual C++
复制代码
#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 );
}


J#
复制代码
import System.*;
import System.IO.*;
import System.Xml.*;

public class Sample
{
    public static void main(String[] args)
    {
        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.get_Target(), newPI.get_Data());

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

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

.NET Framework

受以下版本支持:3.5、3.0、2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:3.5、2.0、1.0

XNA Framework

受以下版本支持:2.0、1.0

参考

XmlDocument 类
XmlDocument 成员
System.Xml 命名空间

你可能感兴趣的:(XmlDocument..::.CreateProcessingInstruction)