Redefine DTD element

44 Views Asked by At

I'm trying to create a DTD that includes OOTB (out-of-the-box) elements imported from another DTD, as well as custom elements.

My goal is to reuse as many definitions as possible, declaring only those elements that are strictly necessary.

For example, I'm trying to create a DTD that validates the following structure:

- <topic>
  - <body>
    - <image>
    - <p>
        - PCDATA
        - <b>
        - <i>

To make things a bit more interesting, the elements , , and should be the ones defined in the external DTD, as they don't require any modification.

For the , and

elements, the idea is to use the OOTB definition but redefine the allowed elements as seen in the structure above.

I have tried importing specific elements only, as well as loading the entire external DTD and redefine the necessary elements, but I haven't had any luck so far. I'm not sure if my approach is correct or if I'm doing something wrong but I'm stuck at a dead end.

Here's the code.

catalog.xml

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
    <public
        publicId="-//TEST//DTD Topic//EN"
        uri="dtd/test.dtd"/>
</catalog>

test.dtd

<?xml version="1.0" encoding="UTF-8"?>
<!ENTITY % topic-type
  PUBLIC "-//TEST//ELEMENTS Topic//EN"
         "topic.mod"
>%topic-type;

topic.mod

<?xml version="1.0" encoding="UTF-8"?>

<!ENTITY % topic            "topic"                                       >
<!ENTITY % body             "body"                                        >


<!ENTITY % elements
  PUBLIC "-//TEST//ELEMENTS Elements//EN"
         "elements.mod"
>%elements;

<!-- ============================================================= -->
<!--                    ELEMENT DECLARATIONS                       -->
<!-- ============================================================= -->

<!ENTITY % topic.content "(%body;)" >
<!ENTITY % topic.attributes "id ID #REQUIRED">
<!ELEMENT  topic %topic.content;>
<!ATTLIST  topic
        %topic.attributes;
        class CDATA "- topic/topic ">

<!ENTITY % body.content "(%image;|%p;)*" >
<!ELEMENT  body %body.content;>
<!ATTLIST  body
        class CDATA "- topic/body ">

elements.mod

<?xml version="1.0" encoding="UTF-8"?>
<!ENTITY % commonElements
        PUBLIC "-//OASIS//ELEMENTS DITA 1.3 Common Elements//EN"
        "commonElements.mod"
        >%commonElements;


<!ENTITY % p.content
        "(#PCDATA       |
               %b;      |
               %i;)*">

<!ENTITY % p.attributes
        ""
        >
<!ELEMENT p     %p.content;>
<!ATTLIST p     %p.attributes;
                class CDATA "- topic/p " >

Any ideas or advice? Thank you in advance.

1

There are 1 best solutions below

0
On

You seem to be customizing not any kind of DTD, you are customizing a DTD for the DITA XML vocabulary. Most people creating DITA DTD vocabulary specializations and constraints follow this tutorial written by Eliot Kimber to create them: http://dita4practitioners.github.io/dita-specialization-tutorials/