When overridden in a derived class, writes out a processing instruction with a space between the name and text as follows: <?name text?>.
Assembly: System.Xml (in System.Xml.dll)
The text would result in a non-well formed XML document.
name is either nullptr or String.Empty.
This method is being used to create an XML declaration after WriteStartDocument has already been called.
An XmlWriter method was called before a previous asynchronous operation finished. In this case, InvalidOperationException is thrown with the message “An asynchronous operation is already in progress.”
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 because the default encoding is UTF-8.
XmlWriter writer = XmlWriter.Create("output.xml"); writer.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-16'"); writer.WriteStartElement("root"); writer.Close();
If text is either nullptr or String.Empty, this method writes a ProcessingInstruction with no data content, for example <?name?>.
If text contains an invalid sequence of "?>", the XmlWriter can either throw an ArgumentException (XmlTextWriter objects) or insert a space "? >" to avoid writing invalid XML (XmlWriter objects created by the Create method).
For the asynchronous version of this method, see WriteProcessingInstructionAsync.