The DTD of a document defines the possible content of an element that can occur in a document. Unfortunately, it is sometimes difficult to read and analyze this definitions. epcEdit simplifies the visualization of the structure of an element by providing railroad diagrams that show the definition of an element in a more intuitive way.
Railroad diagrams are constructed of a limited set of simple building blocks: boxes that represent elements and arrows that are used to connect these boxes.
Elements that must occur within an element are shown as a box with an incoming and outgoing arrow. In order to reach the end of the railroad diagram, a required element must be visited when following the arrows from the start of the diagram.
If two elements must occur in a specific order, these elements will be connected in the railroad diagram by arrows in the same order in which they must occur in the document.
Some elements are optional and can, but do not need to, occur inside another element. In a railroad diagram, such optional elements are shown by drawing a second arrow around that element that joins the outgoing arrow after the element's box representation:
Here, it is possible to bypass the element by following the arrow around the element.
Sometimes, two or more elements can be used alternatively inside another element. If the first element is used, the second element must not occur, and vice versa. Alternatives are shown by a fork in the railroad diagram: To reach the end of the diagram, either path can be followed:
Depending on the DTD, some elements may occur repeatedly in the content of another element. If an element must occur at least once, a backward arrow is shown around the element box in the railroad diagram:
The backward arrow creates a loop around the element box. After visiting the element once, it is possible to follow the looping arrow and visit the element again.
If an element can be used repeatedly, but is not required to occur at least once, then a second arrow is added to the element's box to mark the element as optional:
Here, it is possible to bypass the element by following the upper arrow, but the element can be re-visited any number of times by returning on the lower backward arrow.
There is a final class of element occurrences that can be present in an SGML DTD: A list of elements where each element must occur once, but the order in which the elements occur is not specified. In an SGML DTD, this is expressed using the AND-connector (&). In XML, the AND-connector must not be used, so this construct will never occur in an XML DTD.
AND-groups are difficult to represent in a railroad diagram because of the large number of possible combinations in which the group members can occur. To keep the railroad diagram to a reasonable size, epcEdit shows the AND-group in a compressed notation:
As a real-world example, the railroad diagram for the screenshot element in the DocBook DTD is presented below:
In the DocBook DTD, the screenshot element has a content definition that is shown below:
<!ELEMENT screenshot (screeninfo?,
(graphic | graphicco |
mediaobject | mediaobjectco))>
This content definition states that a screenshot element can start with an optional screeninfo element which must be followed by either a graphic element, a graphicco element, a mediaobject or a mediaobjectco element.
The railroad diagram represents this definition by allowing to bypass the screeninfo element, but one of the remaining elements must be visited to reach the end of the diagram.