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.)
Including a DTD in another DTD
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),
© 2022 - 2024 — McMap. All rights reserved.