Working with XPath inside Orchestrations is a powerful and simple feature of BizTalk 2004. The help guide does a good job describing the process (under Using XPath in Message Assignment).
I have found that the XPath queries can only be done against a Message and the results can be set to a Message, XML Document or other orchestration variables. XPath queries can also be executed against untyped messages. That is, a Message that is of type System.Xml.XmlDocument.
CRITICAL: BizTalk xpath can be used to both read values and set values inside your Message. To set values in your message, you need to be inside a Message Construct shape.
Here are some of the things you can do with xpath and how to do them:
- Set a single values inside a Message using xpath
à xpath(SingleXML, "//LineTotal") = nLineTotal;
- Extract a single piece of data out of a Message
à sCustomer = xpath(InXML,"string(//Customer)");
- Extract a single node out of a large XML Document and assign it to a message or variable
à sXPath = System.String.Format("//Item[{0}]",nCount);
à xDoc = xpath(InXML, sXPath);
- Count the number of nodes or occurrences of something inside your message
à nNumberItems = System.Convert.ToInt32(xpath(InXML, "count(//Item)"));
A great resource for xpath functions and expressions is the W3Schools.
I have put together a sample that shows several different xpath uses inside the Orchestration. This sample takes in an Order, calculates the total per line, sends out each line item as a single message, and sends out the whole order with an order total. Note that the Item nodes are not updated on the Output document, only on the single documents.
DOWNLOAD: XPath Sample
The de-batching approach is based on Darren Jefford’s Blog about Manual Message Splitting. Make sure you check it out and download his sample as well.