Tuesday, January 30, 2007

Note About BizTalk xpath Function

I just wanted to archive some sample code here...I've used the xpath function in BizTalk orchestrations fairly often, but it always takes me a couple of tries to get it right.

Here's a snippet that I have used successfully to assign a value to a field in an EDI 810 document:

n104Path = "/*[local-name()='X12_00401_810']" +
"/*[local-name()='N1Loop1'][3]" +
"/*[local-name()='N1']/*[local-name()='N104']";
xpath(Edi810, n104Path) = Response.myField;


Here's another that I have used to extract the value from the same field in an EDI 810 document (there's a difference in the xpath expression, here I'm using the XPath string() function):

// check n104 element (under "ship to")
n104Path = "string(/*[local-name()='X12_00401_810']" +
"/*[local-name()='N1Loop1'][3]" +
"/*[local-name()='N1']/*[local-name()='N104'])";
n104String = (System.String)xpath(Edi810,n104Path);
n104String = n104String.Trim();


I have seen examples that look like the following, but when I try them the string value is just null:

n104Path = "/*[local-name()='X12_00401_810']" +
"/*[local-name()='N1Loop1'][3]" +
"/*[local-name()='N1']/*[local-name()='N104']/text()";

No comments: