XmlWriter.WriteProcessingInstruction Method (String, String)
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 null 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 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 null 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.
Available since 8
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 8.1