Hi,
XML provides a mechanism that allows the use of the contents of one .xml file inside another. The general idea is outlined
here.
I was playing around with the possibility of using this feature in CiLib to tidy up simulations. For example, I might always use the same problems in different simulations. It would be useful to have those problems in a separate file, say 99Problems.xml, and re-use it in different simulations. Or I may want to run the same simulations on different problems. Then I could substitute the name of the different problems file, or its entity name, in an existing simulation.
I got it working by including the following line in the doctype tag of the main .xml file:
<!DOCTYPE simulator [
<!ENTITY problems SYSTEM "99Problems.xml">
<!ATTLIST algorithm id ID #IMPLIED>
<!ATTLIST problem id ID #IMPLIED>
<!ATTLIST measurements id ID #IMPLIED>
]>
And then putting the following somewhere between the <simulator> tags, before I list the simulations:
&problems;
It also works with algorithms and measurements, i.e. I could factor them out to separate files and include them in the same way. I could not do the same with simulations though.
The factored-out tags must be in their own file, inside <simulator> tags. No tags outside the root <simulator>-tags were required, i.e. no doctype etc. For example, my entire measurements file (at measurements.xml) looks like this:
<simulator>
<measurements id="fitness" class="simulator.MeasurementSuite" resolution="10">
<addMeasurement class="measurement.single.Fitness"/>
</measurements>
</simulator>
I also have algorithms.xml and problems.xml, similarly constructed. All my xml files are in the same directory. My simulator file looks like this:
<?xml version="1.0"?>
<!DOCTYPE simulator [
<!ENTITY algorithms SYSTEM "algorithms.xml">
<!ENTITY problems SYSTEM "problems.xml">
<!ENTITY measurements SYSTEM "measurements.xml">
<!ATTLIST algorithm id ID #IMPLIED>
<!ATTLIST problem id ID #IMPLIED>
<!ATTLIST measurements id ID #IMPLIED>
]>
<simulator>
&algorithms;
&problems;
&measurements;
<simulations>
<!-- all my simulations in here -->
</simulations>
</simulator>
It would be interesting to know why I can't extend this concept to simulations, and if there is perhaps a workaround. I hope others find this helpful.
Regards,
Phlippie