This program takes an XML catalog, and an XML document with a DOCTYPE statement as input, and produces either a DTD as a single file, or an XML document describing the DTD.
DTDs are "flattened" by recursively expanding all entity references.
dtd-flattener [-hV] [--absolute] [--comments] [--xml] [-d=<level>] <output>
<input> <catalog>
Description:
Flattens DTDs for performance or analysis
Parameters:
<output> Output file
<input> Input xml document
<catalog> XML catalog file
Options:
--xml Create XML representation of DTD
--comments Include location comments (default: false)
--absolute Use absolute file paths in comments (default: false)
-d, --debug=<level> Logging level 0-9 (default: 0)
-h, -?, -help, --help Display this help
-V, -version, --version Display version information
JDK 1.8 or greater
NDATA
productions are not handled, e.g.:
<!NOTATION gif PUBLIC "-//CompuServe//NOTATION Graphics Interchange Format 89a//EN"
"image/gif">
<!ENTITY neko SYSTEM "cat.gif" NDATA gif>
The entire entity declaration is ignored if it references a declared notation.
The DTD format produces a valid XML DTD.
The XML format describes elements and their content models, with location information describing which entities definitions were originally found in.
A schema for the XML format can be found in dtd.rnc.
The XML document can be used to parse DTDs programmatically.
Element declarations are represented by a copy of the text from the DTD, followed by an element detailing the content model, e.g.:
<element-declaration name="simpletable">
<location href="../plugins/org.oasis-open.dita.v1_3/dtd/base/dtd/commonElements.mod" line="1558"/>
<raw-content-model>((sthead)?,(strow)+)</raw-content-model>
<content-model element="simpletable">
<group>
<group>
<element name="sthead"/>
</group>
<occur type="?"/>
<sep type=","/>
<group>
<element name="strow"/>
</group>
<occur type="+"/>
</group>
</content-model>
</element-declaration>
To build dtd-flattener.jar:
./gradlew clean build
ls build/libs/dtd-flattener.jar
Kendall Shaw [email protected]
This project moved from https://github.com/queshaw/dtd-normalizer
This program and the accompanying materials are made available under the terms of the Eclipse Public License v. 2.0 which is available at https://www.eclipse.org/legal/epl-2.0/.
SPDX-License-Identifier: EPL-2.0