Integrating Integrators – BizTalk, Windows Azure, Windows Workflow, and Beyond

Using XPath Inside BizTalk Orchestrations

BizTalk Blogs

This group is for blogs related to BizTalk Server. This includes Community Syndicated blogs and Stephen W. Thomas’s blog.

Stephen W. Thomas BizTalk MVP

Insight and guidance on Microsoft BizTalk Server, Windows Azure, Infrastructure as a Service, and related Microsoft technologies.

Using XPath Inside BizTalk Orchestrations

Rate This
  • Comments 8

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.

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Post
  • hey Thomas

    that was gr8 information u knw i implimented that but i am running one small issue if u can help me out,i am appplying same senario with sql adapter i am splitting coming bunch of xml and running loop and xpath for node by node data and i get node xml in message but now i do not know how to insert it into sql table as it is not bound to updategram,how can i achive this????

  • You will need to create a schema to inset that data into SQL.  Or use .net code to do the same.

    You can either create an Update Gram schema or create a stored procedure.  Use the Add Generated Item option to create the schema.

    You should be able to find some samples on this online.

    Stephen W. Thomas

  • Great information, thanks.  The link to the sample files doesn't seem to work anymore, are they still hosted and available somewhere?  Thanks!

  • Sorry things have moved around a bit since this post in 2004.  All samples can now be found here: http://www.biztalkgurus.com/m/

    Thanks.

  • thanks its very help ful for me .

  • hi i saw  your sample xpath application,

    there u mention

    // Get a specific node based on the loop count

    sXPath = System.String.Format("//Item[{0}]",nCount);

    but i have doubt in the item[{0}]

    is curly brace should need inside the square bracket?

    actually i refered in www.w3schools.com/.../xpath_syntax.asp website

    there saying if we want first item element in xml document,

    we should use //item[0]

    but obviously getting error when i omitted the

    curly brace

    can u explain me the index usage?

  • actually i couldnot understand this statement .. can u explain me?

    // Allow unrecognized messages on this send port

    SingleXML(XMLNORM.AllowUnrecognizedMessage) = true;

  • so far i used xml schema for message type in message creating properties

    and       used  default xml pipeline in configuration port

    but in  ur application, u used system.xml.xmldocument in messagetype

    and default pipeline of passthrough used in configuration port

    can u tell me ,   for what purpose  we  using that default pipeline and system.xml.xmldocument?

Page 1 of 1 (8 items)
Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Post