Multi Root Document Types


A single document type with multiple root elements is used to handle varying documents that may exist within a system.


A system needs to handle varying types of documents. These are somehow related, yet each type of document needs a unique identity provided by a document root.


Systems where varying types of documents need to be processed, but the different documents are closely related.


Maintainability of the system is effected by how the document types are organized.


Create a single declaration with multiple root elements for the different document types.


The two documents below show two different bank transactions, a deposit and a withdrawal. The document have different root elements, but many other common elements. Both of these documents use the same DTD, but declare different roots.

<!DOCTYPE "Deposit" SYSTEM "bank.dtd">
<Account id="123"/>
<Amount currency="USD">100.00</Amount>


<!DOCTYPE "Withdrawal" SYSTEM "bank.dtd">
<Account id="123"/>
<Amount currency="USD">100.00</Amount>



Allows the different document types to easily share structure. Having all of the related document types declared in a single file can increase maintainability. However, if revisions need to be made to the different document types separately, it might be better having separate declarations.

Related Patterns

Universal Root and Multiple Document Types are alternatives.

Known Uses

In DocBook (http://www.oasis-open.org/docbook/) the root element can be a set or a book element.