Bill Osuch
Bill Osuch

Reputation: 408

xpath query not working in BizTalk orchestration

I'm trying to rewrite a BizTalk 2010 application and do away with an external assembly, but I seem to be running into xpath problems.

We have a process that stores a healthcare claim (837P) as xml in the database, and we need to extract it later. I have a WCF port calling a stored procedure that returns an xml message that looks something like this:

<ClaimXml_SEL_GetClaimXmlResponse xmlns="http://schemas.microsoft.com/Sql/2008/05/TypedProcedures/dbo">
   <StoredProcedureResultSet0>
      <StoredProcedureResultSet0 xmlns="http://schemas.microsoft.com/Sql/2008/05/ProceduresResultSets/dbo/ClaimXml_SEL_GetClaimXml">
         <Claim><![CDATA[<ns0:X12_00401_837_P (etc.)

So what I need to do is extract the actual 837P message - the part that starts with ns0:X12_00401_837_P.

The helper class is very simple, just has a method like this:

public XmlDocument ExtractClaimXml(XmlDocument xDoc)
{
   XmlDocument xReturn = new XmlDocument();

   XmlNode node = xDoc.SelectSingleNode("/*[local-name()='ClaimXml_SEL_GetClaimXmlResponse' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/TypedProcedures/dbo']/*[local-name()='StoredProcedureResultSet0' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/TypedProcedures/dbo']/*[local-name()='StoredProcedureResultSet0' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/ProceduresResultSets/dbo/ClaimXml_SEL_GetClaimXml']/*[local-name()='Claim' and namespace-uri()='http://schemas.microsoft.com/Sql/2008/05/ProceduresResultSets/dbo/ClaimXml_SEL_GetClaimXml']");

   xReturn.LoadXml(node.InnerText);

   return xReturn;
}

and then the Message Assignment shape has this code:

rawClaimXml = ClaimXmlResponse;
strippedClaim = XmlHelperClass.ExtractClaimXml(rawClaimXml);
Claim837P = strippedClaim;

...where ClaimXmlResponse; is the message shown above, Claim837P is an 837P message, and rawClaimXml & strippedClaim are xml variables. This works just fine, but it seems excessive to call an external assembly.

I tried this in the assingment shape:

rawClaimXml = xpath(ClaimXmlResponse, "same xpath as above");
strippedClaim.LoadXml(rawClaimXml.InnerText);
Claim837P = strippedClaim;

...but get the error "'UnderlyingXmlDocument.InnerText': .NET property is write-only because it does not have a get accessor".

So then I tried just getting a string from the xpath query:

rawClaimString = xpath(ClaimXmlResponse, "string(same xpath as above)");
rawClaimString = rawClaimString.Replace("<![CDATA[", "");
rawClaimString = rawClaimString.Replace(">]]>",">");
strippedClaim.LoadXml(rawClaimString);
Claim837P = strippedClaim;

...but that's no good. Also tried a variant:

rawClaimXml = xpath(ClaimXmlResponse, "same xpath as above");
rawClaimString = rawClaimXml.InnerXml.ToString();
rawClaimString = rawClaimString.Replace("<![CDATA[", "");
rawClaimString = rawClaimString.Replace(">]]>",">");
strippedClaim.LoadXml(rawClaimString);
Claim837P = strippedClaim;

...but still no good. Any suggestions?

Thanks!

Upvotes: 1

Views: 1876

Answers (2)

DTRT
DTRT

Reputation: 11040

1- Here's a couple of things you can try:

  • Wrap the xpath in the string() function. xpath(ClaimXmlResponse, "string(same xpath as above)");
  • Append the /text() node to the xpath. xpath(ClaimXmlResponse, "same xpath as above/text()");
  • A combination of the two.

Can you elaborate on the goal here? There's nothing wrong with using the helper class. If it's the extra Assembly that's bothering you, you can always add the .cs to the BizTalk Project.

2- Coming from a different direction, you can use Path option for the Inbound BizTalk message body on the Messages Tab of the WCF-Custom Adpater configuration.

Upvotes: 4

Suppi Varaabhi
Suppi Varaabhi

Reputation: 1

I was also facing the similar issue but when I gone through your various solution I got the solution for my question.

For me this worked **

rawClaimString = xpath(ClaimXmlResponse, "string(same xpath as above)");

**

thanks for that phew ;)

Coming to the solution for your problem you can distinguishly promote the node that holding your response and try to access that node using .notation and assign it to the sting this ll return the expected output to you :)

Upvotes: 0

Related Questions