XmlDocument..::.CreateProcessingInstruction

来源:互联网 发布:java编译成class工具 编辑:程序博客网 时间:2024/06/16 16:32
.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 XmlDocumentDim target As StringDim data As StringDim returnValue As XmlProcessingInstructionreturnValue = 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 SystemImports System.IOImports System.Xmlpublic 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 subend class
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 );}
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
原创粉丝点击