XPath returns value in C# utility but not in Expression shape in Biztalk

411 Views Asked by At

In the XML message below I can get 'AccountNumber' using

//*[local-name()='AccountNumber']/text()

or

/*[local-name()='GetFullAxxAccountNoResponse']/*[local-name()='GetFullAxxAccountNoResult']/*[local-name()='FullAxxAccNo']/*[local-name()='FullAxxAccountNo']/*[local-name()='AccountNumber']

This works fine in a C# test app or in the Notepad++ XPath plugin, but it does not return anything when used in a BizTalk expression shape, can anyone help flesh this out? I have also tried including the namespace in the top level node but had no luck.

Expression shape code:

vAccount = xpath(mymessage.body, "either one of the xpath statements above")

Instance:

<GetFullAxxAccountNoResponse xmlns="http://temp.org/">
    <GetFullAxxAccountNoResult>
       <FullAxxAccNo>
           <FullAxxAccountNo>
               <AccountNumber>123456</AccountNumber>
           </FullAxxAccountNo>
       </FullxxAccNo>
    <SuccessFlag>success</SuccessFlag>
    <Message />
    </GetFullAxxAccountNoResult>
</GetFullAxxAccountNoResponse>
2

There are 2 best solutions below

0
DTRT On

Those xPaths by themselves will return a Node. To get the text content, you should use a format such as:

xpath(myMessage, "string(//*[local-name()='SomeElement']/text())")

0
Zee On

Instead of using /text(). which returns a text node. you shall use string() function to converting the node to string.

so

xpath(mymessage.body, "string(//*[local-name()='AccountNumber'])")

shall work.

In addition. If you have your schema defined for this message in your biztalk application. promote this field as a distinguished fields in the schema will make your expression looks more clean. you can access this field like this:

vAcccount = mymessage.AccountNumber