Copyright © Cloud Software Group, Inc. All Rights Reserved
Copyright © Cloud Software Group, Inc. All Rights Reserved


Appendix C Creating XML Documents : Understanding Child Documents

Understanding Child Documents
A child XML document is one that is attached to a parent XML document and that is processed at the end of each occurrence in the parent document.
Take the sample tables, ECTS_DEPTS and ECTS_EMPLOYEES. Suppose you want to create an XML document that lists all the departments from ECTS_DEPTS and, for each department, all its employees. You can do that with nested FORALL statements in the TIBCO Object Service Broker rules language, like this:

 
FORALL ECTS_DEPTS:
FORALL ECTS_EMPLOYEES WHERE DEPTNO = ECTS_DEPTS.DEPTNO:
(process one employee)
END;
END;

 
In an XML document, you can perform that task with a child document. For the preceding example, define an XML document for the ECTS_DEPTS table, which then becomes your parent document, and name it PRIMER_DEPTS.
Follow the steps as illustrated by the three figures below to define PRIMER_DEPTS.
 
 
Earlier in this chapter, you created an XML document named PRIMER_EMPS to display a list of employees. Perform the following steps to reuse that document for selecting employees in one department by applying data- selection criteria:
1.
Add the PRIMER_EMPS document to the PRIMER_DEPTS document as a child: Open the XML Documents view and the PRIMER_DEPTS document definition.
2.
3.
Drag PRIMER_EMPS from the XML Documents view into the Select Child Document box on the Child Documents tab. The result should look like this:
 
 
During processing of child documents, their document type is always inherited from the parent document regardless of the type defined in the child document.
Now add a few selection criteria to our child document, keeping in mind that you want to list only the employees in the department currently being processed. In the PRIMER_DEPTS document definition under the Child Documents tab is an area in which to specify parameter values for the table, as appropriate, and any necessary data selection criteria. Those properties override the values that already exist in the child document. That is, you need not revise any of the properties of the child document that would change its function as a parent.
In this case, you do not need any parameter values because the ECTS_EMPLOYEES table is not parameterized. Your selection criterion is to list all the employees in the department currently being processed. Recall that the department number in both tables is in the field DEPTNO. Simply apply the curly-bracket ({}) notation to access the field in the ECTS_DEPTS table to phrase the selection, as shown here:
 
Finally, to test the result, run PRIMER_DEPTS by choosing Run As from the short-cut menu for the selected PRIMER_DEPTS item in the XML Documents view. Here is the output:
 

Copyright © Cloud Software Group, Inc. All Rights Reserved
Copyright © Cloud Software Group, Inc. All Rights Reserved