If a document contains more than one entity declaration using the same entity name, the first entity declaration that is encountered will be used. All subsequent declarations with the same name will be ignored.
If a document contains more than one attribute declaration using the same attribute name, the first attribute declaration that is encountered will be used. All subsequent declarations with the same name will be ignored.
If more than one element declaration has the same element name, a fatal error will be raised by the processor.
Now that you know the rules for processing an XML document, let's look at the processing order that the processor follows:
The internal subset of the DTD is read before everything else. This guarantees that any attribute or entity definitions listed in the internal subset will override any definitions in an externally referenced DTD. Developers can still use external DTDs, but they can override the declarations in the external DTDs.
If the internal DTD contains external parameter entities, these entities will be replaced when the processor reaches them in the DTD. The internal DTD will be expanded to include the replacement text, and the replacement text will be processed. Once this is done, the rest of the internal DTD is processed. If the internal DTD contains additional external parameter entities, they will be replaced in the same manner when the processor reaches them. All general entities will be ignored at this step.
Once the entire internal DTD is processed, any external DTDs referenced in the DOCTYPE declaration using the PUBLIC or SYSTEM keyword will be processed.
Once the internal and external DTDs are processed and validated, the processor will replace general entities in the document body when they are referenced in the document.
Thus, you can create general external DTD documents containing declarations that apply to a large set of applications. You can override entities and attributes in these external DTDs in an internal DTD because the internal DTD will be processed first. Notice that the DTD is validated before the general entities are replaced. This order explains why general entities can never be used in any part of your declarations that are being validated, such as the enumerated values for an attribute.