BizTalk HL7由于空XML元素中的换行而发送管道错误 [英] BizTalk HL7 send pipeline error due to line breaks in empty XML elements

查看:112
本文介绍了BizTalk HL7由于空XML元素中的换行而发送管道错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用BizTalk映射器映射到HL7 A31消息.该地图具有多个内联XSLT脚本功能.

I am mapping to an HL7 A31 message using the BizTalk mapper. The map has several inline XSLT scripting functoids.

通过HL7发送管道放置XML时,它会生成错误:

When the XML is put through the HL7 send pipeline, it generates an error:

元素'ROL_11_OfficeHomeAddress'具有无效的结构

The element 'ROL_11_OfficeHomeAddress' has an invalid structure

如果我查看挂起的消息,则可以看到发生这种情况的原因. ROL_11元素为空,如下所示:

If I look at the suspended message, I can see why this has happened. The ROL_11 element is empty, and looks like this:

    <ROL_11_OfficeHomeAddress>
    </ROL_11_OfficeHomeAddress>

在开始标记和结束标记之间,由于缩进,因此存在换行符和多个空格/制表符.这完全是XSLT生成的,并且我相信是由换行引起的错误.

Between the opening and closing tags, there is a line break and several spaces/tabs due to indenting. This is exactly as generated by the XSLT and I believe it is the line break that is causing the error.

我可以在编写XML之前将XSLT包裹在<xsl:if>语句中以检查值.但是,这个问题在很多地方都发生了,并且像这样包装每个元素似乎都为时过早.

I could wrap the XSLT in an <xsl:if> statement to check for a value before writing the XML. However this problem is occurring in many places and it seems overkill to wrap every single element like this.

我真正想要的是BizTalk自动将元素转换为空元素,如下所示:

What I really want is for BizTalk to automatically convert the element to an empty one, like this:

<ROL_11_OfficeHomeAddress />

我相信这会解决问题.有什么办法可以告诉我做到这一点吗?

I believe this would solve the problem. Is there any way I can tell it to do that?

我已经尝试过的事情:

  • 使用<xsl:strip-space>,但这会引发自己的错误.我认为这是因为BizTalk用其自己的代码包装了内联XSLT,因此在错误的位置指定了带状空间.

  • Using <xsl:strip-space> but that raised its own error. I think this is because BizTalk wraps the inline XSLT in its own code and thus strip-space was specified in the wrong place.

更改地图的网格属性,以将缩进设置为,以希望删除空白.这对挂起的消息中看到的XML没有影响.

Changing the map's grid properties to set Indent to No in the hope the whitespace would be removed. This had no effect on the XML seen in the suspended message.

按照

Adding the registry key for legacy whitespace handling as per this guidance. Again, this appeared to have no effect at all.

推荐答案

如果转换

If you convert your entire map into XSLT, the below will strip out newlines and whitespace and leave you with an empty tag if there isn't anything but whitespace:

<xsl:element name="ROL_11_OfficeHomeAddress">
  <xsl:if test="normalize-space(ROL_11_OfficeHomeAddress)">
    <xsl:value-of select="normalize-space(ROL_11_OfficeHomeAddress)" />
  </xsl:if>
</xsl:element>

修改: Biztalk通常在典型的1:1可裁剪元素映射中生成如下所示的XSLT

Edit: Biztalk usually generates XSLT like the following in a typical 1:1 nillable element mapping

    <xsl:variable name="var:v2" select="string(ns0:ROL_11_OfficeHomeAddress/@xsi:nil) = 'true'" />
    <xsl:if test="string($var:v2)='true'">
      <ns0:ROL_11_OfficeHomeAddress>
        <xsl:attribute name="xsi:nil">
          <xsl:value-of select="'true'" />
        </xsl:attribute>
      </ns0:ROL_11_OfficeHomeAddress>
    </xsl:if>
    <xsl:if test="string($var:v2)='false'">
      <ns0:ROL_11_OfficeHomeAddress>
        <xsl:value-of select="ROL_11_OfficeHomeAddress/text()" />
      </ns0:ROL_11_OfficeHomeAddress>
    </xsl:if>

因此,如果您确实使用过<xsl:strip-space>,则意味着该元素将仅在空白处映射到<ROL_11_OfficeHomeAddress></ROL_11_OfficeHomeAddress>,除非您遍历该映射将其更改回<xsl:element>.

So if you did use <xsl:strip-space> it would mean that the element would map to <ROL_11_OfficeHomeAddress></ROL_11_OfficeHomeAddress> if whitespace only, unless you went through the map changing it back to <xsl:element>.

您可以尝试使用如下所示的调用模板(nodeXfrm是一个节点)

What you could try is to use a call template like the below (nodeXfrm is a node)

<xsl:template name="StripElement">
    <xsl:param name="nodeXfrm"></xsl:param>
    <xsl:variable name="nodeName">
        <xsl:value-of select="local-name($nodeXfrm)"></xsl:value-of>
    </xsl:variable>
    <xsl:element name="{$nodeName}">
        <xsl:if test="normalize-space($nodeXfrm)!=''">
            <xsl:value-of select="$nodeXfrm/text()"/>
        </xsl:if>
    </xsl:element>
</xsl:template>

然后在地图中,您可以通过这种方式为需要剥离的每个元素调用模板

And then within your map you can call the template for each element you need stripped in this way

  <xsl:call-template name="StripElement">
    <xsl:with-param name="nodeXfrm" select="ROL_11_OfficeHomeAddress"></xsl:with-param>
  </xsl:call-template>

XSLT专家也许可以更优雅地做到这一点

An XSLT guru might be able to do this more elegantly

这篇关于BizTalk HL7由于空XML元素中的换行而发送管道错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆