This documentation is archived and is not being maintained.

XmlWriter.WriteProcessingInstruction Method

When overridden in a derived class, writes out a processing instruction with a space between the name and text as follows: <?name text?>.

[Visual Basic]
Public MustOverride Sub WriteProcessingInstruction( _
   ByVal name As String, _
   ByVal text As String _
public abstract void WriteProcessingInstruction(
 string name,
 string text
public: virtual void WriteProcessingInstruction(
 String* name,
 String* text
) = 0;
public abstract function WriteProcessingInstruction(
   name : String,
 text : String


The name of the processing instruction.
The text to include in the processing instruction.


Exception Type Condition
ArgumentException The text would result in a non-well formed XML document.

name is either a null reference (Nothing in Visual Basic) or String.Empty.

This method is being used to create an XML declaration after WriteStartDocument has already been called.


This method can be used to write the XML declaration (rather than WriteStartDocument). This could result in the encoding attribute being incorrectly written. For example, the following C# code would result in an invalid XML document.

XmlTextWriter writer = new XmlTextWriter("pi.xml", Encoding.UTF8);
writer.WriteProcessingInstruction("xml", "version='1.0', encoding='UTF-16'");

If text is either a null reference (Nothing in Visual Basic) or String.Empty, this method writes a ProcessingInstruction with no data content, for example <?name?>.


See WriteProcessingInstruction (in the XmlTextWriter class) for an example using this method.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

XmlWriter Class | XmlWriter Members | System.Xml Namespace