How to map an array to fixed fields using Biztalk mapper
I need to remap an array of objects like this:

    <Root>
      <ListOfObjs>
        <Obj>
          <Attr1>0000</Attr1>
          <Attr2>Hello!</Attr2>
        </Obj>
        <Obj>
          <Attr1>1111</Attr1>
          <Attr2>Hello1!</Attr2>
        </Obj>
      </ListOfObjs>
    </Root>
in an output like this:

        <Root>
            <Obj1_Attr1>0000</Obj1_Attr1>
            <Obj1_Attr2>Hello!</Obj1_Attr2>
            <Obj2_Attr1>1111</Obj2_Attr1>
            <Obj2_Attr2>Hello1!</Obj2_Attr2>
        </Root>
So in my XSD schema I have something like this:

Schema Input

                           <xs:element name="Root">
                            <xs:complexType>
                             <xs:sequence>
                              <xs:element name="ListOfObjs">
                               <xs:complexType>
                                <xs:sequence>
                                 <xs:element name="Obj">
                                  <xs:complexType>
                                   <xs:sequence>
                                    <xs:element name="Attr1">
                                     <xs:simpleType>
                                      <xs:restriction base="xs:string">
                                       <xs:minLength value="1"/>
                                       <xs:maxLength value="50"/>
                                      </xs:restriction>
                                     </xs:simpleType>
                                    </xs:element>
                                   <xs:element name="Attr2">
                                    <xs:simpleType>
                                      <xs:restriction base="xs:string">
                                       <xs:minLength value="1"/>
                                       <xs:maxLength value="50"/>
                                      </xs:restriction>
                                     </xs:simpleType>
                                    </xs:element>
                                   </xs:sequence>
                                  </xs:complexType>
                                 </xs:element>
                                </xs:sequence>
                               </xs:complexType>
                              </xs:element>
Schema output

                                 <xs:element name="Root">
                                  <xs:complexType>
                                   <xs:sequence>
                                    <xs:element name="Obj1_Attr1">
                                     <xs:simpleType>
                                      <xs:restriction base="xs:string">
                                       <xs:minLength value="1"/>
                                       <xs:maxLength value="50"/>
                                      </xs:restriction>
                                     </xs:simpleType>
                                    </xs:element>
                                   <xs:element name="Obj1_Attr2">
                                    <xs:simpleType>
                                      <xs:restriction base="xs:string">
                                       <xs:minLength value="1"/>
                                       <xs:maxLength value="50"/>
                                      </xs:restriction>
                                     </xs:simpleType>
                                    </xs:element>
                                    <xs:element name="Obj2_Attr1">
                                    <xs:simpleType>
                                      <xs:restriction base="xs:string">
                                       <xs:minLength value="1"/>
                                       <xs:maxLength value="50"/>
                                      </xs:restriction>
                                     </xs:simpleType>
                                    </xs:element>
                                    <xs:element name="Obj2_Attr2">
                                    <xs:simpleType>
                                      <xs:restriction base="xs:string">
                                       <xs:minLength value="1"/>
                                       <xs:maxLength value="50"/>
                                      </xs:restriction>
                                     </xs:simpleType>
                                    </xs:element>
                                   </xs:sequence>
                                  </xs:complexType>
                                 </xs:element>
In addiction I have to evaluate every single value because when I found some conditions (like if value=0000 output should be NULL).

What would be the best way to do it? I'm thinking to develop a custom functoid but I'm not sure it would be the best way, probably it could be done even using XSLT inline transforms, can you point me in the best direction?

Thank you

  • Edited by Caioshinn 18 hours 19 minutes ago
November 5th, 2014 12:20pm

Hi,

You cannot directly map an array output to any single field in BizTalk mapper.

Couple of options :

1) create the Xslt or inline C# code

Refer: 

http://seroter.wordpress.com/2008/10/07/splitting-delimited-values-in-biztalk-maps/

2) Shankycheil has provided a solution to similar requirement in the below link, u can also refer that.

https://social.msdn.microsoft.com/Forums/en-US/55ec472d-4f34-4057-b1c6-0e50740f0f6e/how-to-itterate-string-array-values-in-biztalk-mapper?forum=biztalkgeneral

Rachit


Free Windows Admin Tool Kit Click here and download it now
November 5th, 2014 12:28pm

Hi Caioshinn,

As per my understating I can suggest you two ways to go ahead with this .

1) As being blogged by Seroter link here  Link

2 ) Or Else Create an class Object of your Source Schema  which will contain  array of <Obj> and then assign the object to the destination schema object through array iteration.

Thanks

Abhishek 

November 5th, 2014 2:53pm

Hi Caioshinn,

As per my understating I can suggest you two ways to go ahead with this .

1) As being blogged by Seroter link here  Link

2 ) Or Else Create an class Object of your Source Schema  which will contain  array of <Obj> and then assign the object to the destination schema object through array iteration.

Thanks

Abhishek 

Thank you very much, speaking about the first solution, in the example there is an array in a single string, delimited by a fixed char, but it's not my situation because I have an array of complex elements each composed by a certain number of fields.

About the second proposal, what do you mean more precisely? I understand that you mean that I have to create a class that represents my object Obj, but remember that in my output XML I don't want to have any Obj instance, but I need to have its fields (attr1, attr2) mapped to certain fixed values (ob1_attr1, obj2_attr2, and so on)


  • Edited by Caioshinn 13 hours 41 minutes ago
Free Windows Admin Tool Kit Click here and download it now
November 5th, 2014 5:00pm

Hi,

You cannot directly map an array output to any single field in BizTalk mapper.

Couple of options :

1) create the Xslt or inline C# code

Refer: 

http://seroter.wordpress.com/2008/10/07/splitting-delimited-values-in-biztalk-maps/

2) Shankycheil has provided a solution to similar requirement in the below link, u can also refer that.

https://social.msdn.microsoft.com/Forums/en-US/55ec472d-4f34-4057-b1c6-0e50740f0f6e/how-to-itterate-string-array-values-in-biztalk-mapper?forum=biztalkgeneral

Rachit


Thank you, I already seen both posts, but I'm not sure they are what I need or I can't understand well how to use them.

Speaking about the first solution, as I told before, in the example I should have an array already formed and delimited by a char (something like "obj1attr1-obj1attr2-ob2attr1-obj2attr2". In this situation probably this example could be a good point to start from, but how to transform my complex input object in a similar formatted string?

About the second I don't understand well what is the working solution that they have adopted. Is the 4 steps solution suggested by  Shankycheil? If yes, how can I loop between all array elements and extract all their values?

November 5th, 2014 5:10pm

Your requirement looks suspicious. The source schema is easy to parse. The target schema is NOT easy to parse. So you want to make a simple message more complex. Is there a good reason
Free Windows Admin Tool Kit Click here and download it now
November 6th, 2014 2:48am

Your requirement looks suspicious. The source schema is easy to parse. The target schema is NOT easy to parse. So you want to make a simple message more complex. Is there a good reason
November 6th, 2014 4:03am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics