[ Download Code ]
Firstly, what is an XML processing instruction? A processing instruction (PI) is a tag that encodes specific application information which begins with <? and ends with ?>. An XML document can contain multiple processing instructions for different applications. There are two parts to a processing instruction, a target and a value. The target acts like a name and the value is the string after the target. The value can consist of multiple tokens.
<?target value?>
What about the XML declaration, is it a processing instruction? Yes, it is a special processing instruction. It is a special kind of processing instruction that has a defined format for its value. Another common example of a processing instruction is for adding stylesheets. The stylesheet processing instruction also has a defined format for its value, which contains several pseudo-attributes. Pseudo because they act like a normal element's attributes.
<?xml-stylesheet href="standardstyle.css" title="Standard Stylesheet" type="text/css"?>
Otherwise the format of a processing instruction's value is open. Processing instructions are not part of the document's data, rather are more like comments and are overlooked by the XML parser which simply passes them on to the client application.
Microsoft's application InfoPath uses processing instructions to indicate that the XML file should be viewed within the InfoPath client.
<?mso-application progid="InfoPath.Document"?>
A second processing instruction, mso-infoPathSolution, tells InfoPath where the location of the solution template is located. The template contains information on the transformation for the layout, any and all views as well as the expected schema of the XML file and any data sources.
So how do we work with an XML document's processing instructions from within a C# application?