Question

I try to transform a hierarchical XML file to a flat file schema using Biztalk 2010.

It works fine. Every file is mapped. But the hierarchy is destroyed.

My input xml structure looks like this:

<root>
    <node>
        <element1></element1>
        <element2></element2>
        <subnode1>
            <element1></element1>
            <element2></element2>
        </subnode1>
        <subnode2>
            <element1></element1>
            <element2></element2>
        </subnode2>
    </node>
</root>

The flat file schema looks like this:

<root>
    <node>
        <element1></element1>
        <element2></element2>
    </node>
    <subnode1>
        <element1></element1>
        <element2></element2>
    </subnode1>
    <subnode2>
        <element1></element1>
        <element2></element2>
    </subnode2>
</root>

My input is like this:

<root>
    <node>
        <element1>Test1</element1>
        <element2>Test2</element2>
        <subnode1>
            <element1>Sub11</element1>
            <element2>Sub12</element2>
        </subnode1>
        <subnode2>
            <element1>Sub21</element1>
            <element2>Sub22</element2>
        </subnode2>
    </node>
    <node>
        <element1>Test3</element1>
        <element2>Test4</element2>
        <subnode1>
            <element1>Sub31</element1>
            <element2>Sub32</element2>
        </subnode1>
        <subnode2>
            <element1>Sub41</element1>
            <element2>Sub42</element2>
        </subnode2>
    </node>
</root>

What I expect as output is:

Test1;Test2
Sub11;Sub12
Sub21;Sub22
Test3;Test4
Sub31;Sub32
Sub41;Sub42

But what I get is:

Test1;Test2
Test3;Test4
Sub11;Sub12
Sub21;Sub22
Sub31;Sub32
Sub41;Sub42

Any ideas how I can make Biztalk keep the hierarchy?

Was it helpful?

Solution

I don't have the BizTalk Mapper at hand right now so I only can provide a Xslt solution but basically it will illustrate that you need your map to iterate over your node elements to preserve the structure.

If you want to achieve this using pure BizTalk Mapping you need a grouping node in your flat output structure to connect your source node element to which will force the map to create the for-each loop like in the following Xslt:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
    <xsl:output method="text" indent="no" />

    <xsl:template match="/">
        <xsl:for-each select="root/node">
            <xsl:value-of select="element1" />
            <xsl:text>;</xsl:text>
            <xsl:value-of select="element2" />
            <xsl:text>&#xA;</xsl:text>
            <xsl:value-of select="subnode1/element1" />
            <xsl:text>;</xsl:text>
            <xsl:value-of select="subnode1/element2" />
            <xsl:text>&#xA;</xsl:text>
            <xsl:value-of select="subnode2/element1" />
            <xsl:text>;</xsl:text>
            <xsl:value-of select="subnode2/element2" />
            <xsl:text>&#xA;</xsl:text>
        </xsl:for-each>
    </xsl:template>

</xsl:stylesheet>

You may need to adjust the line breaks (&#xA;) to your output schema needs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top