Re: Problems with multiple multiple-level inclusion of DTDs

Discussion in 'XML' started by Peter Flynn, Jul 26, 2008.

  1. Peter Flynn

    Peter Flynn Guest

    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
     
    Peter Flynn, Jul 26, 2008
    #1
    1. Advertising

  2. Peter Flynn

    Peter Flynn Guest

    wrote:
    > On Jul 26, 4:40 pm, Peter Flynn <> wrote:

    [snip]
    >> 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.

    >
    > This is what I am doing for now, though users of a.dtd and b.dtd have
    > to manually manage inclusion.
    >
    > Another possibility I thought of is to have an exclude-base-
    > includers.dtd file that sets all PE switches to false. This file would
    > be included by base.dtd. Each includer of base.dtd would set the its
    > own PE switch to true, and then include base.dtd. End users are hidden
    > from all this mess, but the downside of this approach is that the
    > exclude-base-includers.dtd file needs to be maintained.


    It's usually far easier to manage if you make base.dtd the external
    entity referenced by the DOCTYPE Declaration, and let users add their
    own selection of a, b, ... using a PE in the internal subset.

    <!DOCTYPE whatever SYSTEM "/some/uri/for/base.dtd" [
    <!ENTITY % a "INCLUDE">
    ]>

    and do all your entity management and file inclusion in base.dtd, a.ent,
    b.ent, or whatever.

    ///Peter
     
    Peter Flynn, Jul 27, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Clifford W. Racz
    Replies:
    4
    Views:
    2,039
    Clifford W. Racz
    Feb 13, 2004
  2. David Tucker

    multiple dtds namspaces

    David Tucker, Sep 8, 2004, in forum: XML
    Replies:
    1
    Views:
    449
    Richard Tobin
    Sep 8, 2004
  3. pabbu
    Replies:
    8
    Views:
    735
    Marc Boyer
    Nov 7, 2005
  4. Replies:
    11
    Views:
    1,245
    Ian Collins
    Aug 5, 2006
  5. Trans
    Replies:
    2
    Views:
    86
    Trans
    Aug 31, 2007
Loading...

Share This Page