我需要我的 BizTalk 映射停止将 xml:lang 转换为 ns1:lang
我在 BizTalk 2009 中有一个映射,它将一些数据转换为 XML 文档以发送到另一个系统。目标架构包括一些带有 xml:lang
属性的元素。 BizTalk 将其生成为 ns1:lang
。目标系统要求使用前缀xml
。
下面是一个简化的示例,展示了 BizTalk 正在执行的操作:
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
<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
前缀?
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.
Here is a simplified example to show what BizTalk is doing:
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
<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>
Example of map output
<ns0:example xmlns:ns0="http://example.com/"
xmlns:ns1="http://www.w3.org/XML/1998/namespace"
ns1:lang="en-US" />
Is there some way to convince BizTalk to use the xml
prefix?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
据我所知,没有内置的方法可以实现这一目标。
然而,我可以看到两种解决方案:
使用自定义 XML 样式表
如果您在地图上右键单击并仔细查看生成的 xsl 样式表,您将看到一个 XML 命名空间声明,例如this:
这是 BizTalk 映射器的默认行为,您对此无能为力。但是,如果您继续提取生成的 XSLT 并将其用作地图的后端,则可以更改此声明以匹配预期结果。
生成的 xsl 样式表如下所示:
现在您可以使用此自定义样式表作为地图的后端。
使用自定义管道组件
您所追求的是消息对于您的目标收件人来说是正确的。因此,我们的想法是在 BizTalk 外部发送消息时更改有问题的命名空间前缀。转换发生在发送管道的处理期间。
Nic Barden 发表了博客并提供了一些源代码关于此内容。您可以使用他的示例作为执行命名空间前缀替换的基础,而不是替换命名空间本身。
我强烈建议您查看他撰写的有关开发流管道组件的整个系列文章。 Nic 做了广泛而彻底的工作,描述了编写强大的企业级管道组件所需的所有内容。
As far as I know, there is no builtin way for achieving this.
There are, however, two solutions that I can see:
Use a Custom XML StyleSheet
If you right-clik on the map and look carefully in the generated xsl stylesheet, you'll see a XML namespace declaration like this:
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.
The resulting xsl stylesheet looks like this:
Now you can use this custom stylesheet as a backend for the map.
Use a Custom Pipeline Component
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 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.
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.
更简单的方法是在模式定义的开头添加命名空间声明,如下所示。
The easier way to do it and have everything work is to just add the namespace declaration at the beginning of the schema definition like this.
除了 Maxime 的建议之外,以下是我发现的其他可能性:
忽略它并希望供应商的 API 能够接受它。
我认为这行不通。当我测试映射时,BizTalk 给出以下错误:
输出验证错误:前缀“ns1”无法映射到为“xml”或“xmlns”保留的命名空间名称。
您好,BizTalk!?您是决定使用 ns1 的人。别向我抱怨这件事!
使用基于 XSL 的脚本 functoid 强制输出。
这是基于 我在 BizTalk 论坛上收到的建议。它要求我们伪造输出模式以使用虚拟属性,该属性由 functoid 替换为 xml:lang 属性。`
添加搜索/替换表达式
采用调用映射的编排并添加它后面的表达式将获取我们发送给供应商的 XML,并通过搜索/替换正则表达式运行它以修复命名空间前缀。
In addition to Maxime's suggestions, here are the other possibilities I've found:
Ignore it and hope that the vendor’s API will take it.
I don’t think this will work. When I test the map, BizTalk gives me this error:
Output validation error: Prefix 'ns1' cannot be mapped to namespace name reserved for "xml" or "xmlns".
Hello, BizTalk!? You’re the one who decided to use ns1. Don’t complain about it to me!
Use an XSL-based script functoid to force the output.
This is based on the suggestion I received on the BizTalk forums. It requires that we fudge the output schema to use a dummy attribute that gets replaced with the xml:lang attribute by the functoid.`
Add a search/replace expression
Take the orchestration that calls the map and add an expression after it that would take the XML we’re sending to the vendor and run it through a search/replace regex to fix the namespace prefixes.