It seems as though every orchestration I’m trying to xpath something either into or out of a message in BizTalk. So I’m creating a simple cheat sheet that I can refer to.

To set a single value inside a message:

xpath(msg_YourMessage, “Node Instance XPath”) = str_YourValue;

To extract a single value from a Message:

str_YourValue = (System.String)xpath(msg_YourMessage,”string(Node Instance XPath)”);

Note: I like casting the xpath result to a System.String so I can have complete access to all the System.String methods/properties inside of the Expression Shape

Extract a single value from a looping segment by index:

str_Xpath= System.String.Format(“Node Instance XPath[{0}]”,int_Index);

xDoc = xpath(msg_YourMessage, str_Xpath);

Count the number of nodes inside the message:

int_NumberofNodes = System.Convert.ToInt32(xpath(msg_YourMessage, “count(Node Instance Xpath)”));