|
|
junyang@xxxxxxxxx wrote:
> Hi all,
>
> I have one DTD fragment, base.dtd, that contains a bunch of useful
> element definitions (say an element named "base"), and two DTD
> fragments, a.dtd and b.dtd, that each build on base.dtd and defines a
> few more elements. I use an entity to include base.dtd in a.dtd and
> b.dtd. For example, in a.dtd:
>
> <!ENTITY % include.base SYSTEM "base.dtd">
> %include.base
> <!ELEMENT a (base+)>
>
> In b.dtd:
>
> <!ENTITY % include.base SYSTEM "base.dtd">
> %include.base
> <!ELEMENT b (#PCDATA|base)*>
>
> In my XML documents, if I just want to use element a (or b), I simply
> need to entity-include a.dtd, and that will automatically include
> base.dtd, which is nice.
>
> However, the trouble comes in when I entity-include both a.dtd and
> b.dtd. The problem is that the element "base" will be included twice
> (once via a.dtd->base.dtd and another time via b.dtd->base.dtd). Note
> that multiple definitions of the "include.base" entity is fine (as per
> XML standard), but multiple definitions of any element is disallowed.
The technique is to use parameter-entity switches.
In a.dtd:
<!ENTITY % use.base.from.a "INCLUDE">
<![%use.base.from.a;[
%include.base;
<!ENTITY % use.base.from.b "IGNORE">
]]>
In b.dtd
<!ENTITY % use.base.from.b "INCLUDE">
<![%use.base.from.b;[
%include.base;
<!ENTITY % use.base.from.a "IGNORE">
]]>
This way, whichever one you invoke first will prevent the other one from
being activated.
Better would be to paramaterise a and b alone, and invoke your base in
your document type declaration with a PE switch to include whichever or
a and b (or both) that you require for the instance.
///Peter
|
|