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)
Parameters
- name
-
Type:
System::String^
The name of the processing instruction.
- text
-
Type:
System::String^
The text to include in the processing instruction.
| Exception | Condition |
|---|---|
| ArgumentException | 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. |
| InvalidOperationException | 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 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
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1