XML Data Merging

The ListSheet HTML Component (HTC) can be instantiated in several different modes. Many of these modes present data in a hierarchical fashion, allowing details to be hidden, drilled into, and then hidden again. When operating in this manner, the ListSheet HTC expects data to be represented hierarchically in the corresponding XML data-island. This is achieved by merging either two (or three) distinct single-tiered XML data-islands into a single two-tiered (or three-tiered) data-island. The following routines, provided by the Commerce Server Business Desk Framework, perform data merging of this sort:

sMergeGroups2 (server-side) sMergeGroups2 (client-side)
sMergeGroups3 (server-side) sMergeGroups3 (client-side)
xmlMergeGroups2 (server-side) xmlMergeGroups2 (client-side)
xmlMergeGroups3 (server-side) xmlMergeGroups3 (client-side)
xmlMergeGroupsByID2 (client-side)
xmlMergeGroupsByID3 (client-side)

The following example illustrates how XML data merging works for two levels. A three level merge is conceptually similar. The following XML representation of two records is considered to be the higher-level information, containing in this case the name and age of different people, to be displayed in the group rows of a ListSheet HTC (the userid is configured to be hidden).

<xml id=master>
    <document recordcount=2>
        <record>
            <name>David</name>
            <age>39</age>
            <userid>dav001</userid>
        </record>
        <record>
            <name>Sarah</name>
            <age>33</age>
            <userid>sar015</userid>
        </record>
    </document>
</xml>

The following XML representation of three records is considered to be the detailed information, containing in this case the names and ages of the children of the people in the XML structure above, to be displayed in the detail rows of a ListSheet HTC (the userid is configured to be hidden).

<xml id=detail>
    <document recordcount=2>
        <record>
            <userid>sar015</userid>
            <name>Jennifer</name>
            <age>6</age>
        </record>
        <record>
            <userid>sar015</userid>
            <name>Thomas</name>
            <age>3</age>
        </record>
        <record>
            <userid>dav001</userid>
            <name>Lilly</name>
            <age>10</age>
        </record>
    </document>
</xml>

A variety of MergeGroups routines can be used to combine either two or three sets of XML records, resulting in a two- and three-tier set of records appropriate for use with a two- or three-level ListSheet HTC. If the two XML structures above are represented in two XML document objects referenced by the variables xmlMaster and xmlDetail, respectively, they could be merged by calling the following routine, which places the resulting merged XML in the string variable sMerged:

sMerged = sMergeGroups2(xmlMaster, xmlDetail, "userid")

The field element name userid is passed in as the key. It must be an element that exists in both sets of records. If a record in the master set and a record in the detail set are found to have the same value for the specified element, the two records are merged in the resulting set, with the master record elements occupying the first-tier of the result record and the detail record elements occupying the second-tier of the result record.

The following XML representation shows the result of combining the two sets of records above. The merged, second-tier fields are shown in bold font. Note that the key element, at least, appears on both tiers of the result records:

<xml>
    <document recordcount=2>
        <record>
            <name>David</name>
            <age>39</age>
            <userid>dav001</userid>
            <record>                <userid>dav001</userid>                <name>Lilly</name>                <age>10</age>            </record>
        </record>
        <record>
            <name>Sarah</name>
            <age>33</age>
            <userid>sar015</userid>
            <record>                <userid>sar015</userid>                <name>Jennifer</name>                <age>6</age>            </record>            <record>                <userid>sar015</userid>                <name>Thomas</name>                <age>3</age>            </record>
        </record>
    </document>
</xml>


All rights reserved.