Stephen W. Thomas BizTalk Blog

100% Pure BizTalk
posts - 133, comments - 215, trackbacks - 425

My Links

News

Subscribe to my blog via:


Add to Google

Visit my website at:
www.BizTalkGurus.com

Archives

BizTalk 2004 Samples

BizTalk 2006 Samples

BizTalk Videos

BizTalk White Papers

BizTalkBlogs.com

Great BizTalk Blogs

Other Links

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 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.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Print | posted on Monday, October 25, 2004 10:30 PM |

Powered by: