Including a DTD in another DTD
Asked Answered
S

1

12

Is it possible to include a DTD in another DTD? (I don't mean copy-and-paste the second DTD into the first DTD. I mean to have something like a pointer to the second DTD in the first DTD.)

Sopping answered 17/6, 2011 at 17:51 Comment(1)
Very similar to this question: #6259866Fixed
R
13

Yes, It's possible. One way is to use parameter entity, which can be used within the DTD. Let's look at example:

XML file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note SYSTEM "first.dtd" [
    <!ELEMENT type (#PCDATA)> <!-- you can also add DTD here -->
]>
<note>
    <type>business</type>
    <to>George W.</to>
    <from>Me</from>
    <heading>meeting</heading>
    <body>Meet me in central park at 16</body>
</note>

First (referencing) DTD:

<!ELEMENT note (type,to,from,heading,body)>
<!ENTITY % elements SYSTEM "second.dtd">
%elements;

Second (referenced) DTD:

<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>

As checked with Oxygen XML you can even make third DTD, which is referenced from second and so on. However you can't use recursive entity references e.g.:

elements1.dtd:

<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ENTITY % elements2 SYSTEM "elements2.dtd">
%elements2;

elements2.dtd:

<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
<!ENTITY % elements1 SYSTEM "elements1.dtd">
%elements1;

[Xerces] Recursive entity reference "%elements1". (Reference path: %elements1 -> %elements2 -> %elements1),

Ramtil answered 17/6, 2011 at 20:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.