ATTLIST and enumerations

Discussion in 'XML' started by Manfred Lotz, Feb 24, 2014.

  1. Manfred Lotz

    Manfred Lotz Guest

    Hi there,
    I have an enumeration in a DTD which will be used at different places.

    Minimal example:

    <!ATTLIST mydoc
    bla CDATA #REQUIRED
    myenum (v1|vx|s|a) #IMPLIED>
    ....
    <!ATTLIST comment
    name CDATA #REQUIRED
    myenum (v1|vx|s|a) #IMPLIED>

    I don't want to have the enum list at different places in the DTD.

    Is it possible to have an enumeraton defined in one place of a DTD and
    refer to this in different ATTLIST statements?
     
    Manfred Lotz, Feb 24, 2014
    #1
    1. Advertisements

  2. Manfred Lotz

    Manfred Lotz Guest

    Ok, I found it. Here is the solution, just for the records.


    <!ENTITY % enumtype "myenum (v1|vx|s|a) #IMPLIED">

    and then
    !ATTLIST mydoc
    bla CDATA #REQUIRED
    %enumtype;>
     
    Manfred Lotz, Feb 24, 2014
    #2
    1. Advertisements

  3. Manfred Lotz

    Peter Flynn Guest

    Yes, that's the standard way to reuse a specification fragment.
    Most of the larger popular DTDs do this.

    It's also possible to put the list in an external text file, eg

    v1|
    vx|
    s|
    a

    and declare it as an external entity, then use the entity reference in
    the ATTLIST declaration. That way the list can be maintained externally
    to the DTD, sometimes by a non-XML person who doesn't have to edit the
    DTD to keep the list up to date.

    ///Peter
     
    Peter Flynn, Feb 24, 2014
    #3
  4. Manfred Lotz

    Manfred Lotz Guest

    You are right, this is also possible. In my case I prefer to have it in
    the DTD itself.
     
    Manfred Lotz, Feb 27, 2014
    #4
  5. Manfred Lotz

    Peter Flynn Guest

    Yes, it's only really useful when the list has to be maintained by a
    third party, or perhaps by a database (eg part numbers).

    ///Peter
     
    Peter Flynn, Feb 27, 2014
    #5
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.