我需要BizTalk映射来停止将xml:lang转换为ns1:lang [英] I need my BizTalk map to stop converting xml:lang to ns1:lang

查看:84
本文介绍了我需要BizTalk映射来停止将xml:lang转换为ns1:lang的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在BizTalk 2009中有一个映射,该映射正在将一些数据转换为XML文档以发送到另一个系统.目标模式包括一些具有xml:lang属性的元素. BizTalk将其生成为ns1:lang.目标系统要求使用前缀xml.

I have a map in BizTalk 2009 that is converting some data into an XML document to be sent on to another system. The target schema includes some elements with xml:lang attributes. BizTalk generates those as ns1:lang. The target system requires that the prefix xml be used.

这是一个简化的示例,用于显示BizTalk的功能:

Here is a simplified example to show what BizTalk is doing:

sample.xsd

sample.xsd

<xs:schema targetNamespace="http://example.com/"
           xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:import schemaLocation="common.xsd"
             namespace="http://www.w3.org/XML/1998/namespace" />
  <xs:element name="example">
    <xs:complexType>
      <xs:attribute ref="xml:lang" />
    </xs:complexType>
  </xs:element>
</xs:schema>

common.xsd

common.xsd

<xs:schema xmlns:xml="http://www.w3.org/XML/1998/namespace"
           targetNamespace="http://www.w3.org/XML/1998/namespace"
           xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:attribute name="lang" type="xs:language" />
</xs:schema>

地图输出示例

<ns0:example xmlns:ns0="http://example.com/"
             xmlns:ns1="http://www.w3.org/XML/1998/namespace"
             ns1:lang="en-US" />

是否可以说服BizTalk使用xml前缀?

Is there some way to convince BizTalk to use the xml prefix?

推荐答案

据我所知,没有内置的方法可以实现这一目标.

As far as I know, there is no builtin way for achieving this.

但是,我可以看到两种解决方案:

There are, however, two solutions that I can see:

使用自定义XML样式表

如果您在地图上右键单击并仔细查看所生成的xsl样式表,则会看到如下所示的XML名称空间声明:

If you right-clik on the map and look carefully in the generated xsl stylesheet, you'll see a XML namespace declaration like this:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:ns1="http://www.w3.org/XML/1998/namespace"
                ...
                >
...
<xsl:attribute name="ns1:lang">
...

这是BizTalk映射器的默认行为,您不能对此做任何事情.但是,如果继续提取生成的XSLT并将其用作地图的后端,则可以更改此声明以匹配预期结果.

This is the default behaviour of the BizTalk mapper and you cannot do anything about it. However, if you proceed to extract the generated XSLT and use this as the backend for your map, you can change this declaration to match the expected outcome.

  • 首先,将样式表复制到项目位置.
  • 将此样式表作为文件包含在BizTalk项目中
  • 更新样式表,以使名称空间声明和匹配的属性前缀正确.

生成的xsl样式表如下:

The resulting xsl stylesheet looks like this:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xml="http://www.w3.org/XML/1998/namespace"
                ...
                >
...
<xsl:attribute name="xml:lang">
...

现在,您可以使用此自定义样式表作为地图的后端.

Now you can use this custom stylesheet as a backend for the map.

  • 在Visual Studio中,打开地图.
  • 在BizTalk设计器图面上的空白处单击任何地方.
  • 在地图属性中,找到自定义XSL路径,然后指定自定义样式表的位置.
  • In Visual Studio, open the map.
  • Click anywhere on a blank space in the BizTalk designer surface.
  • In the map properties, locate the Custom XSL Path and specify the location of your custom stylesheet.

使用自定义管道组件

您要寻找的是该消息对您的目标收件人是正确的.因此,想法是更改有问题的名称空间前缀,作为在BizTalk外部发送消息的一部分.转换发生在发送管道的处理过程中.

What you're after is that the message is correct for your target recipient. So the idea is to change the offending namespace prefix as part of sending the message outside BizTalk. The transformation happens during the processing of the send pipeline.

Nic Barden 博客并提供了一些源代码关于此这里.您可以使用他的样本作为执行替换名称空间前缀的基础,而不是替换名称空间本身.

Nic Barden has blogged and provided some source code about this here. You can use his sample as the basis for performing replacement of namespace prefixes, rather than replacing namespaces themselves.

我强烈建议您查看他完成的有关开发流传输管道组件的所有系列文章. Nic做了详尽而详尽的工作,描述了编写强大的企业级管道组件所需的全部内容.

I strongly encourage you to check out the whole series of posts he's done about Developing Streaming Pipeline Components. Nic has made an extensive and thorough job of describing all that's needed to author robust and enterprise-class pipeline components.

  • Part 1
  • Part 2
  • Part 3
  • Part 4
  • Part 5

这篇关于我需要BizTalk映射来停止将xml:lang转换为ns1:lang的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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