public WriteProcessingInstruction ( string name, string text ) : void | ||
name | string | |
text | string | |
return | void |
using System.Xml; XmlTextWriter writer = new XmlTextWriter("file.xml", System.Text.Encoding.UTF8); writer.WriteProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"stylesheet.xsl\""); writer.Close();
using System.Xml; XmlTextWriter writer = new XmlTextWriter("file.xml", System.Text.Encoding.UTF8); writer.WriteStartElement("root"); writer.WriteProcessingInstruction("pi", " or & characters]]>"); writer.WriteEndElement(); writer.Close();This code creates a new XmlTextWriter object that writes to a file named "file.xml" using UTF-8 encoding. It then writes a start element with the name "root". After that, it calls the WriteProcessingInstruction method to write a processing instruction with a target of "pi" and some CDATA that contains some text that might contain special characters. Finally, it writes an end element to close the root element. Package Library: This code makes use of the System.Xml.XmlTextWriter class, which is part of the .NET Framework Class Library.
public WriteProcessingInstruction ( string name, string text ) : void | ||
name | string | |
text | string | |
return | void |