2011-03-31 77 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

相關問題