XPath Inside Orchestrations in BizTalk 2004

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.

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:

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.

This article is part of the GWB Archives. Original Author: Stephen W. Thomas

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.