Correlating more than one element
The docbook chapter "Importing XML into Objects" has the following tip:
You can call the Correlate() method repeatedly to correlate more than one element, although the examples in this chapter show only one correlation.
Does anyone have a good example of multiple correlations? I've got code running that does multiple imports of the same file while changing the correlation and it's inelegant and not really what I want.
Product version: Caché 2017.1
$ZV: Cache for Windows (x86-64) 2017.1.1 (Build 111U_SU) Tue May 23 2017 13:20:26 EDT
Hi Peter,
Correlate() simply associates the given XML element with the given ObjectScript class. %XML.Reader allows you to specify multiple element/class associations by calling Correlate() multiple times. Subsequent calls to Next() will return the objects associated with the elements you've correlated, in the order in which they are found in the file. Here is a very basic example using two classes
Here are the classes:
And our XML file:
Now we can read both objects in one pass with the following method:
In a more complex example, you would probably want to call Next() in a loop, and actually pay attention to the error code, but this should demonstrate the point.
I hope this helps.
Very helpful. Thanks!