A source-driven connection enables you to automatically map mixed content (text and child nodes) in the same order as in the XML source file. A mixed-content connection is shown as a dotted line at parent-node level (see Mapping the <para> element). This topic explains how to map mixed content. It also shows the effect of using standard (target-driven) connections with mixed content.
|Note:||Source-driven connections can also be used in database fields with mixed-content (Professional and Enterprise editions).|
|Note:||In order to accept mixed content, target components must have mixed-content nodes.|
Mapping mixed content
This topic explains how to map mixed content using a source-driven connection. You will need the following files: Tut-OrgChart.xml, Tut-Orgchart.mfd, Tut-Person.xsd, and Tut-OrgChart.xsd, which are available in the Tutorial folder.
Source XML instance
A snippet of Tut-OrgChart.xml is shown below. In this example, we will focus on the mixed-content element <para> with its child nodes <bold> and <italic>. The <para> element also contains a processing instruction (<?sort alpha-ascending?>) and a comment (<!--Company details... -->), both of which can also be mapped, as shown below. Note the sequence of the text and bold/italic nodes in the XML instance file.
Mapping the <para> element
The image below illustrates a portion of Tut-Orgchart.mfd. In the example below, the dotted line shows that the <para> element has mixed content. To create mixed-content connections, take the following steps:
1.Select the menu command Connection | Auto Connect Matching Children, which will connect matching child nodes automatically. Alternatively, you can manually map the <para> node with its child nodes.
2.Connect the <para> item in the source component with the <para> item in the target component. A message box will ask if you would like to define the connection as source-driven.
3.Click Yes to create a mixed-content connection.
4.Click the Output pane to see the result of the mapping. Click the button (Wrap) in the Output pane toolbar to view the full (i.e., not going beyond the scroll bar) code listing in the Output pane. The mixed content of the <para> node has been mapped in the same order it appears in the XML source file.
Processing instructions and comments
If your mapping has processing instructions and/or comments and you want to map them, take the steps below:
1.Right-click the mixed-content connection (dotted line) and select Properties.
2.Under Source-Drive (Mixed content), select the check boxes Map Processing Instructions and/or Map Comments.
Target-driven connections with mixed content
Choosing target-driven connections for mixed content may have undesirable consequences. To see how target-driven connections affect the order of mixed-content nodes, follow the instructions below:
1.Open Tut-OrgChart.mfd from the Tutorial folder.
2.Press the toolbar button (Auto Connect Matching Children). Clear the check box Create copy-all connections in the settings for matching-children connections. This will prevent MapForce from creating copy-all connections automatically.
3.Create a connection between the para node in the source and the para node in the target. A message will ask if you would like to define the connections as source-driven. Click No. This creates a target-driven connection.
4.Click the Output pane to see the result of the mapping (screenshot below).
The screenshot above shows that the content of the text() item in the source has been mapped to the target. However, the order of the child nodes (bold and italic) in the output corresponds to the order of these nodes in the target XML schema. This means that the bold and italic elements are not integrated into the text but are mapped separately.