Mapping xml string to any type as xml element in BizTalk map

293 Views Asked by At

I have a BizTalk map that look like this:

map

The string concat look like this:

map string concat

when I test this map I get this output:

output

what I need is this output:

enter image description here

Can anyone tell me how I can get the shown output, where the .. tags and all the sub tags is not a string but is xml element tag..? I Need to do this in the shown BizTalk Map!

I have now made a small VS project where you can test and see how to solve my problem. You can download the project from this link:

Visual Studio Project

For the test project map the input is this:

<ns0:SomeData xmlns:ns0="http://CustomSchemaMapping.SourceSchema">
  <ID>0</ID>
  <NAME>Test Person</NAME>
  <YEAR>2022</YEAR>
</ns0:SomeData>

and the output should be like this:

<ns0:OutputData xmlns:ns0="http://CustomSchemaMapping.OutputSchema">
    <OtherElement>Test</OtherElement>
    <BrevparamXML>
        <DATA>
            <ID>0</ID>
            <NAME>Test Person</NAME>
            <YEAR>2022</YEAR>
        </DATA>
    </BrevparamXML>
</ns0:OutputData>

and NOT like this:

<ns0:OutputData xmlns:ns0="http://CustomSchemaMapping.OutputSchema">
    <OtherElement>Test</OtherElement>
    <BrevparamXML>  &lt;DATA&gt;&lt;ID&gt;0&lt;/ID&gt;&lt;NAME&gt;Test Person&lt;/NAME&gt;&lt;YEAR&gt;2022&lt;/YEAR&gt;&lt;/DATA&gt;
    </BrevparamXML>
</ns0:OutputData>
2

There are 2 best solutions below

5
Martin Bring On

Is your output schema only used for one integration and you are always going to send the same "Any"-xml? Then I would change the outgoing schema to include those elements. The outgoing xml will be the same anyway and no one else will be affected.

0
Martin Bring On

I tried with a Scripting Functoid of type "Inline XSLT Call Template" with following template and got the desired output. Label the inputs ID, NAME and YEAR. You need to tweak my code to get it to validate. Probably add a namespace from SourceSchema.xsd.

XSLT Template

   <xsl:template name="MyXsltConcatTemplate">
    <xsl:param name="ID" />
    <xsl:param name="NAME" />
    <xsl:param name="YEAR" />

    <xsl:element name="BrevparamXML">
        <xsl:element name="DATA">
            <xsl:element name="ID">
                <xsl:value-of select="$ID" />
            </xsl:element>
            <xsl:element name="NAME">
                <xsl:value-of select="$NAME" />
            </xsl:element>
            <xsl:element name="YEAR">
                <xsl:value-of select="$YEAR" />
            </xsl:element>
        </xsl:element>
    </xsl:element>
</xsl:template>

Result

<ns0:OutputData xmlns:ns0="http://CustomSchemaMapping.OutputSchema">
    <OtherElement>Test</OtherElement>
    <BrevparamXML>
        <DATA>
            <ID>2022</ID>
            <NAME>0</NAME>
            <YEAR>Test Person</YEAR>
        </DATA>
    </BrevparamXML>
</ns0:OutputData>