Provide a single root element that contains an option of multiple elements. Often used for different transaction types within a single document type.
There are several different types of document that need to be processed. Providing a single root element allows for all of the different types of document to be defined by a single DTD. When a processor receives this document, it will know which type of document to expect by inspecting the child element of the root element.
Universal Root is useful when a system has several different, but related, document types to be processed. A transactional processor would be an example of such a system.
Having multiple, distinct document types can increase the maintenance burden of a system. Document types that may be related, but are declared in separate files can start to stray from commonalities that can be taken advantage of.
Create a document type that has a single root element.
(AddAddress | RemoveAddress | UpdateAddress)>
<AddressBookEntry> ... </AddressBookEntry>
In this example an online address book application is being developed. There are several transactions that can take place, lick adding new entries, deleting entries, updating entries.
This allows a way for several related types of documents to be grouped into a single document type structure. A processing system will always know which DTD to expect, but can still handle the documents differently based on the first nested element type. This makes sharing common definitions between the different document easy.
This is also a way that multiple XML document can be gathered into a single larger document. For example a log file might consist of several fragments, for example:
<Time>Jan 15, 1999 10:58AM</Time>
<Time>Jan 15, 1999 11:02AM</Time>
<Event>Message Received from Bob</Event>
Since there is no root element in the file it cannot be processed "as is". To process this, one can prepend a start tag, for example "<LogFile>", in front of the file, and append the end tag "</LogFile>" to the end of the file to be able to process it as a single XML document.
Multi Root Document Types
Multiple Document Types
are alternatives to this pattern.