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 simplecheatsheetthat I can refer to.
To set a single value inside a message:
xpath(msg_YourMessage, "Node InstanceXPath") = str_YourValue;
To extract a single value from a Message:
str_YourValue = (System.String)xpath(msg_YourMessage,"string(Node InstanceXPath)");
Note: I like casting thexpathresult 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 InstanceXPath[{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 InstanceXpath)"));