How to get the root node name of an xml document /node name of any xml element using XPath name() function in Expression Shape BizTalk Server with Examples

Hi, this posts explains how to use XPath Expressions to get the Node Name of an XML Document.
The Xpath expression can be used inside the Expression shape of BizTalk server using the xpath function.

If the business process is tied to the XML then Root Node name can be used to identify the business process being executed in BizTalk Server.

We can get the Root Node name or name of any node using the name() function, by passing  XPath as input parameter

Syntax:
name(XPath Expression)

Example

Input XML
<OrderId>
<OrderRecord>
       <Place>ALT</Place>
       <Date>21-Aug-2011</Date>
</OrderRecord>
<OrderNo>123</OrderNo>
</OrderId>
i) name(/*) 
Result: OrderId

ii) name(/*/*)
Result: OrderRecord

iii) name(/*/*[2])
Result: OrderId


Note – If we need to get the value of the node then use the string function
i.e.  string(/*/*)
Result: ALT21-Aug-2011

Usage in BizTalk Server:
We can use Xpath Expressions in BizTalk Server inside Expression shape

strVariable = xpath(InMsg,"name(/*)");

Here,
strVariable – is a variable of String type since xpath function of Biztalk returns values as a string
InMsg – Name of the message for which we need to find the name of the Root Node
Name(/*) - Name function containing the XPath for the Root Element


The above method can be used on Typed and UnTyped message 

2 comments:

Anonymous said...

Nice Simple Article. More Examples is helpful

Anonymous said...

nice explaination,thank you so much
here /* means xpath instance right???