XPaths in BizTalk- Message Assignment and Expression Shape

In BizTalk, you can assign an XPath value to a message part using an XPath function. This function can also be used to assign a value to an XPath that refers to a message part. It can be used in both the message assignment and expression shapes. In the following section, we will describe how to set an XPath value and retrieve it using XPath.

How to set a value using XPath?

xpath(msgGetInputMessage,”/*[local-name()=’procLoadFile’ and namespace-uri()=’http://schemas.microsoft.com/Sql/2008/05/TypedProcedures/dbo’]/*[local-name()=’Data’ and namespace-uri()=’http://schemas.microsoft.com/Sql/2008/05/TypedProcedures/dbo’]”) = varXmlData;

How to get a value using XPath?

varFileName = xpath(msgOutputMessage,”/*[local-name()=’Request’ and namespace-uri()=’http://TestBizBAM3.Request’]/*[local-name()=’Header’ and namespace-uri()=’http://TestBizBAM3.Request’]/*[local-name()=’ReqID’ and namespace-uri()=’http://TestBizBAM3.Request’]”);

Here are some important points to remember regarding XPath:

  • It’s not recommended to use XPath for repeating tags, whether they are elements or attributes.
  • To obtain the instance XPath query from either an attribute or an element, follow these steps: – Open the schema in Visual Studio and click on the desired element or attribute – Check the property window and copy the complete Instance XPath (as shown in the picture of XPath)
  • To avoid any data conversion errors, it is recommended to retrieve values using the appropriate datatype function such as string, number, etc.

varFileName = xpath(msgOutputMessage,”string(xpath query)”);
varFileSize = xpath(msgOutputMessage,”number(xpath query)”);
varRecordsCount = xpath(msgOutputMessage,”count(copy xpath node value from schema)”);

Post a comment

Leave a Comment

Scroll to Top