. NET Framework class library XmlDocument...:. CreateProcessingInstruction Method
Updated: February 1, November 2007
CreateXmlprocessinginstruction.
Namespace:System. xml
Assembly:System. Xml (in System. Xml. dll)
Syntax
Visual Basic (Declaration)
Public Overridable Function CreateProcessingInstruction ( _ target As String, _ data As String _) As XmlProcessingInstruction
Visual Basic (usage)
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
Parameters
-
Target
-
Type:
System...:. String
The name of the Processing Instruction.
-
Data
-
Type:
System...:. String
Process command data.
Return Value
Type:System. xml...:. xmlprocessinginstruction
The new XmlProcessingInstruction.
Remarks
Although this method creates a new object in the context of the document, it does not automatically add the new object to the document tree. To add a new object, you must explicitly call one of the node insertion methods.
Based on W3C Extensible Markup Language (XML) 1.0 recommendations (www.w3.org/TR/1998/REC-xml-19980210), ProcessingInstruction nodes can be included in the Document node and Element node, and when the EntityReference node is not a child of the Attribute node, the ProcessingInstruction node can also be included in the EntityReference node.
Example
The following example creates a ProcessingInstruction node and adds it to the document.
Visual Basic
Copy code
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
C #
Copy code
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 ++
Copy code
#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 #
Copy code
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
Platform
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 and. NET Compact Framework do not support all versions of each platform. For a list of supported versions, see. NET Framework System Requirements. Version Information
. NET Framework
Supported by the following versions: 3.5, 3.0, 2.0, 1.1, and 1.0
. NET Compact Framework
Supported by the following versions: 3.5, 2.0, and 1.0
XNA Framework
Supported by the following versions: 2.0 and 1.0. For more information, see
Reference
Xmldocument class
Xmldocument Member
System. xml namespace