Creating InfoPath Processing Instructions in BizTalk Server 2004
InfoPath has a little bit of magic in it. I’m not talking about the cool features for creating and using rich XML based forms, but I mean the magic that happens when you save the contents of an InfoPath form in a XML file. Although the result is just a file with the XML extension, it seems even the Windows Explorer is enchanted, it displays an InfoPath icon for the XML file. When double click the file, InfoPath will be opened, the corresponding InfoPath form will be loaded and the data from the XML file is showed in the form.
So what’s causing of all this wizardry? If you open the XML file with Visual Studio.NET for example so we can see the actual XML content, you can see that are some XML directives (starting with ?mso) that you wouldn’t expect:
These tags are called Processing Instructions (PIs). Processing instructions are used to provide information in an XML document that the XML parser passes on to the calling application. PIs are primarily used to tell an application how to handle the data contained within an XML document. PIs must begin with an identifier called a target, which follows rules similar to those for element (XML element: An XML structure that consists of a start tag, an end tag, and the information between the tags. Elements can have attributes and can contain other elements.) and attribute (XML attribute: An XML structural construct. A name-value pair, separated by an equal sign and included in a tagged element, that modifies features of an element. All attribute values are text strings and must be enclosed in quotation marks.) names. Targets are case-sensitive and must start with a letter or underscore. The rest of the target can contain letters, numbers, hyphens, underscores, periods, and colons. Any valid XML textual characters can appear after the target. PIs can be placed anywhere in an XML document outside of other markup. They can be placed in the prolog, following the root element, or within the value of an element. They are usually placed in an XML document's prolog. (description from Office Online) Notice that the PIs also contain a reference to the published InfoPath form. In the example the form is located on my hard disk, but in real-world scenario’s it probably would have been in SharePoint or a file share.
So what got these PIs to do with BizTalk? Yesterday Scott Woodgate briefly mentioned the importance of the PIs in his webcast about BizTalk and InfoPath: when BizTalk picks up a message originating from InfoPath, the PIs could get lost when you process the message. Or if you have a BizTalk orchestration that would construct a new InfoPath message, you will probably want to add the PIs to that message so InfoPath will be used when the message is opened by a user. The first scenario is when you transform an InfoPath XML message using the BizTalk Mapper. By default the PIs will get lost, so the resulting message won’t have the PIs, but you can easily change this. There’s a property for the Grid of the map: “Copy Processing Instructions“; if you set this to Yes, PIs will be preserved in the new message.
A second way of adding PIs to a message in BizTalk is using expressions. You can write following code in an Expression or Assignment shape:
NewExpense = Expense;
NewExpense(XMLNORM.ProcessingInstructionOption) = 1;
NewExpense(XMLNORM.ProcessingInstruction) = "<?mso-infoPathSolution solutionVersion=\"1.0.0.1\" productVersion=\"11.0.6250\" PIVersion=\"1.0.0.0\" href=\"file:///C:\\InfoPath\\ExpenseReport.xsn\" name=\"urn:schemas-microsoft-com:office:infopath:ExpenseReport:-myXSD-2004-04-20T07-24-16\" ?><?mso-application progid=\"InfoPath.Document\"?>";
The value of the ProcessingInstructionOption property can be used as follows:
- 0: New processing instructions from the XML Assembler are appended to the processing instructions at the beginning of the document.
- 1: New processing instructions from the XML Assembler overwrite existing processing instructions at the beginning of the document.
- 2: Processing instructions at the beginning of the document are removed.
Finally the third way of adding PIs is using a custom send pipeline. Add a new Send Pipeline to your BizTalk project and in the Assemble Stage of the pipeline add a XML Assembler. Now you can set the “Add processing instructions text” property of that XML Assembler to the desired PIs. To every message send through this send pipeline, the PIs will be attached.
Conclusion? InfoPath and BizTalk work great together! Like Scott said: “InfoPath is to BizTalk as Outlook is to Exchange“. Check out his blog post about the webcast for more examples about InfoPath and BizTalk. If you've missed the webcast yesterday you can watch it on-demand when it becomes available (usually in 72 hours). Btw, there are a lot of intresting webcasts comming.