views:

106

answers:

1

We are using XML to define a schema for controlling the contents which can be displayed in a diagramming tool. The schema file specifies what kinds of object can be placed on the diagram, how they can be linked together, and what properties these objects have (that is, what settable properties apper in the editor).

When a new kind of diagram is needed, a new schema is written, and is validated against an .xsd. In order to make the schema file more modular and easier to maintain, we are using declarations to include seperate files. Lists of properties etc. which belong together on a particular diagram element, but which might appera in several places in the schema, are written ina seperate xml file, and then inclused at the relevant place. Say:

<!-- Nameing etc. just as an example -->
<!ENTITY CommonProerties1 SYSTEM "file:../CommonProperties1.xml">
<!ENTITY CommonProerties2 SYSTEM "file:../CommonProperties2.xml">

and then somewhere in the schema:

<Node shape="Square">
    &CommonProperties1;
    <!-- Specific properties go here -->
</Node>

This prevents a lot of copy pated stuff that makes maintaining difficult, and lets commmpn properties be shared with multiple schemas too.

The trouble is that now, some of the common properties also have base elements, such as groups of flags and enums etc. I would like to make each file (such as "CommonProperties1.xml") be able to include from another base set such as "CommonEnums.xml", but I don't think this is possible using !ENTITY declaractions.

You can't declare an !ENTITY outside of a !DOCTYPE header, and if you add the header then it makes the top level xml file invalid as it gets a header declaration 1.2 way through the file.

Has anyone ever tried to do similar things, and what did you do to work round / solve the problem? Is there a better option I'm missing?

Cheers for any help,

xan

+1  A: 

General system entities were designed to be used as a text include / replacement mechanism. I've seen deeply nested structures with boilerplate of vast complexity.

So let's dig a little deeper into your problem statement.

In your example, why do you think you can't have an !ENTITY declaration for CommonEnums in the document type declaration such that the entity referency &CommonEnums would be recognized when the containing entity is parsed? What is special about these system entities that you are having trouble declaring? If your goal is to avoid having to declare them during the parse of the document prologue, then, no, you can't get around that.

You can't declare an !ENTITY outside of a !DOCTYPE header

This is true in a sense, but there's a useful loophole. You can declare general entities in an external DTD, in which case their declaration is not physically visible in the document prologue. I don't know if this is helpful in your situation, but declaring your external general system entities in a DTD would allow you to "hide" them from document instances and fragments that refer to them.

If as I suspect your goals are reusability, modularity, and terseness, then I think you can do what you want by means of an external DTD. But to leverage this feature you may have to take on all the work of creating a DTD, more or less, to whatever extent is required to satisfy your XML processor, which will probably insist on validating your document structures against the DTD.

kmcorbett
Not possible to do what we were hoping for, thanks for your advice.
xan