Debatching in xmlDisassembler using envelope schema, failing on empty message

604 views Asked by At

I am debatching an incoming xml messages in BizTalk receive pipeline using an envelope schema. The debatching works well for any xml that contains the sub message I am trying to debatch but fails if the message does not contain any sub message.

I have set the "min occurs" to 0 and nillable = true in the schema for the elements that are in the xpath for debatching. In the sample below the "entry" and "resource" elements have min occurs set to 0, which I thought would let the debatching function work when there is nothing to be debatched.

Here is the annotation for the envelope schema.

<xs:annotation>
   <xs:appinfo>
     <schemaInfo xmlns="http://schemas.microsoft.com/BizTalk/2003" is_envelope="yes"/>
   </xs:appinfo>
</xs:annotation>
<xs:element name="Bundle">
   <xs:annotation>
      <xs:appinfo>
         <recordInfo xmlns="http://schemas.microsoft.com/BizTalk/2003" body_xpath="/*[local-name()='Bundle' and namespace-uri()='']/*[local-name()='entry' and namespace-uri()='']/*[local-name()='resource' and namespace-uri()='']"/>
     </xs:appinfo>
</xs:annotation>

Example message with no messages to debatch

<Bundle >
   <type value="searchset"/>
   <total value="0"/>
</Bundle>

Example of xpath for debatching when sub messages are present.

<Bundle >
   <type value="searchset"/>
   <total value="46"/>
   <entry>
       <resource>
           <Encounter>

Any message that contains the entry/resource/encounters element debatches successfully, but the messages that do not contain the "entry" element ( has no messages to debatch) throw the error below.

Reason: This Disassembler cannot retrieve body nodes using this XPath: "/[local-name()='Bundle' and namespace-uri()='']/[local-name()='entry' and namespace-uri()='']/[local-name()='resource' and namespace-uri()='']". /[local-name()='Bundle' and namespace-uri()='']/[local-name()='entry' and namespace-uri()='']/[local-name()='resource' and namespace-uri()='']

I would expect the messages with nothing to debatch to simply "disappear", but instead I end up with an error in group hub. Any ideas or suggestion on how to get rid of this error would be greatly appreciated.

2

There are 2 answers

4
Ed Bangga On BEST ANSWER

You can use below body_xpath to extract only the 'Bundle' with 'entry' records

body_xpath="/*[local-name()='Bundle' and namespace-uri()=''][*[local-name()='entry' and namespace-uri()=''][count(*)>0]]/*[local-name()='entry' and namespace-uri()='']/*[local-name()='resource' and namespace-uri()='']"

or

body_xpath="/*[local-name()='Bundle' and namespace-uri()=''][*[local-name()='entry' and namespace-uri()=''][count(*)&gt;0]]/*[local-name()='entry' and namespace-uri()='']/*[local-name()='resource' and namespace-uri()='']"
5
Dijkgraaf On

That is because you are pointing the body at the resource node, which does not even exists when there is no message to debatch. You need to be pointing at the a node that always exists in the envelope under which the body messages occur.

What you probably need is the following for emtpy

<Bundle >
   <type value="searchset"/>
   <total value="0"/>
   <entries/>
</Bundle>

and the following for messages.

<Bundle >
   <type value="searchset"/>
   <total value="46"/>
   <entries>
       <entry>
           <resource>
               <Encounter>

And point your body_xpath at entries.