2011-03-31 69 views
1

我正在使用biztalk 2009,需要帮助进行映射。我有输入,如:将集合映射为字符串到目标节点

<root> 
    <shop> 
     <product> 
      <type>1</type> 
      <code>ab</code> 
      <desc></desc> 
     </product> 
     <product> 
      <type>2</type> 
      <code>cd</code> 
      <desc></desc> 
     </product> 
    </shop> 
    <address /> 
    <names /> 
</root> 

我想要的产品集合映射到目标元素作为XML字符串,看起来像这样: <products><product type="1" code="ab" /><product type="2" code="cd" /></products>

我已经找到了解决方案使用自定义的XSLT,但我不想使用它,因为我们发现它很变幻无常。有没有什么functoids可以为我做一些自定义脚本?我也是C尖锐的开发谢谢!

回答

2

这是完全可以用一个简单的地图开箱。

这里是索里XML文件:

<root> 
    <shop> 
     <product> 
      <type>1</type> 
      <code>ab</code> 
      <desc></desc> 
     </product> 
     <product> 
      <type>2</type> 
      <code>cd</code> 
      <desc></desc> 
     </product> 
    </shop> 
    <address /> 
    <names /> 
</root> 

这里是源模式:

<?xml version="1.0" encoding="utf-16"?> 
<xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:element name="root"> 
    <xs:complexType> 
     <xs:sequence> 
     <xs:element name="shop"> 
      <xs:complexType> 
      <xs:sequence> 
       <xs:element minOccurs="1" maxOccurs="unbounded" name="product"> 
       <xs:complexType> 
        <xs:sequence> 
        <xs:element name="type" type="xs:string" /> 
        <xs:element name="code" type="xs:string" /> 
        <xs:element name="desc" type="xs:string" /> 
        </xs:sequence> 
       </xs:complexType> 
       </xs:element> 
      </xs:sequence> 
      </xs:complexType> 
     </xs:element> 
     <xs:element name="address"> 
      <xs:complexType /> 
     </xs:element> 
     <xs:element name="names"> 
      <xs:complexType /> 
     </xs:element> 
     </xs:sequence> 
    </xs:complexType> 
    </xs:element> 
</xs:schema> 

这里的目标模式:

<?xml version="1.0" encoding="utf-16"?> 
<xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:element name="products"> 
    <xs:complexType> 
     <xs:sequence> 
     <xs:element minOccurs="1" maxOccurs="unbounded" name="product"> 
      <xs:complexType mixed="true"> 
      <xs:attribute name="type" type="xs:string" /> 
      <xs:attribute name="code" type="xs:string" /> 
      </xs:complexType> 
     </xs:element> 
     </xs:sequence> 
    </xs:complexType> 
    </xs:element> 
</xs:schema> 

这里是图:

BizTalk Map for Source and destination schemas

这里是输出:

<products> 
    <product type="1" code="ab" /> 
    <product type="2" code="cd" /> 
</products> 

武装witht他的结果,你可以按照在他的博客马克布林布尔概述两个建议之一。

How to copy the entire node to element of string type in a map

+0

嗨克里斯感谢您的快速响应 - 我不能在目标元素上创建子元素,因此创建一个xml字符串的原因将被映射到没有子元素的单个元素。我不能改变的目标模式......它somethign像这样: – dvr 2011-03-31 19:51:41

+0

' ' – dvr 2011-03-31 19:56:00

+0

更具体的目标输出看起来就像这样: ' <![CDATA []]> ' – dvr 2011-03-31 19:58:15

0

我很抱歉地说,这可是当映射变得过于参与并没有明显的方式映射器要做到这一点我只是退回到指定的消息内的.NET辅助方法,其中将建成输出消息。

帮助程序方法可以将biztalk消息作为XLANGMessage类型的参数并返回一个XMLDocument类型,该类型将被转换为您的目标消息类型,如果xml内部正确呈现该类型。

例如:

public static XmlDocument HelperMethod (XLANGMessage message) 
{ 
    var sourceType = (SourceType)message[0].RetrieveAs(typeof(SourceType)); 
    var targetType = new TargetType(); 

    // ... Do target type population and serialization to XmlDocument here 

    return targetAsXmlDoc; 
} 

这将是容易做到这里面.NET所以只是把它变成.NET去做。对不起,所有的映射大师在那里!

+0

或使用自定义xslt。 – 2011-04-06 05:57:20

+0

抱歉,所有那些指责BizTalk表现糟糕的黑客大师。 – Filburt 2011-04-06 13:38:19

+0

我参与过的大多数biztalk项目都是解决方案中最不重要的方面。我希望**不是这种情况,但在大多数BizTalk解决方案中,很少看到需要在亚秒或甚至秒内测量的延迟。 – 2011-04-08 12:40:05

相关问题