XProcessingInstruction Class
Namespace: System.Xml.Linq
Assembly: System.Xml.Linq (in System.Xml.Linq.dll)
Summary
Represents an XML processing instruction. A processing instruction can be used to embed application-specific data in an XML document.
Syntax
public sealed class XProcessingInstruction : XNode
Constructors
| Signature | Description |
|---|---|
XProcessingInstruction(string target) | Initializes a new instance with the specified target. |
XProcessingInstruction(string target, string data) | Initializes a new instance with the specified target and data. |
Properties
| Name | Type | Description |
|---|---|---|
Data | string | Gets or sets the content of the processing instruction. |
Target | string | Gets the target of the processing instruction. |
NodeType | XmlNodeType | Always returns XmlNodeType.ProcessingInstruction. |
Methods
| Signature | Description |
|---|---|
string ToString(SaveOptions options) | Returns the XML representation of the node using the specified options. |
void WriteTo(XmlWriter writer) | Writes the node to an XmlWriter. |
void AddAfterSelf(params object[] content) | Adds content after this node. |
void AddBeforeSelf(params object[] content) | Adds content before this node. |
Example
Creating a processing instruction and adding it to an XDocument:
XDocument doc = new XDocument(
new XProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"style.xsl\""),
new XElement("root",
new XElement("child", "Content")
)
);
Console.WriteLine(doc);
Remarks
The Target property identifies the application to which the processing instruction applies. The Data property contains the instruction's content.
Show/Hide Additional Notes
Processing instructions are not part of the document content and are typically ignored by XML parsers that do not recognize the target.