Modular XML construction using <!ENTITY> references

28 views
Skip to first unread message

Phlippie Bosman

unread,
May 10, 2013, 2:45:25 PM5/10/13
to cilib...@googlegroups.com
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

Andries Engelbrecht

unread,
May 13, 2013, 4:05:35 AM5/13/13
to cilib...@googlegroups.com

Thanks Phlippie!
--
You received this message because you are subscribed to the Google Groups "cilib-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cilib-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

-- 
==========================================================
Prof Andries P Engelbrecht
South African Research Chair in Artificial Intelligence

Fundamentals of Computational Swarm Intelligence,
John Wiley & Sons, December 2005.

Computational Intelligence, An Introduction
John Wiley & Sons, Second edition to be published soon

Computational Intelligence Research Group:
       http://cirg.cs.up.ac.za

Department of Computer Science
School of Information Technology
University of Pretoria
Pretoria 0002, South Africa
Tel: +27 12 420 3578     Fax: +27 12 362 5188
http://www.cs.up.ac.za/~engel
================================================

This message and attachments are subject to a disclaimer. Please refer to www.it.up.ac.za/documentation/governance/disclaimer/ for full details. / Hierdie boodskap en aanhangsels is aan 'n vrywaringsklousule onderhewig. Volledige besonderhede is by www.it.up.ac.za/documentation/governance/disclaimer/ beskikbaar.

Gary Pamparà

unread,
May 13, 2013, 4:40:01 AM5/13/13
to cilib...@googlegroups.com
Hi Phlippie,

The manner in which the simulator application used the XML is very much in a non-standard way. The original design mimicked spring, which has been shown to have been a little shortsighted.

Currently the simulator allows for the algorithm / problem / measurements to be externalized (mainly the way the internal XML processing is handled) but the simulation tags are needed directly.

There is no real workaround to this at the moment - this could be regarded as a limitation.
Reply all
Reply to author
Forward
0 new messages