SYSTEM vs PUBLIC Identifier in XML DTD

When declaring an external Document Type Definition (DTD) in an XML document, the SYSTEM and PUBLIC identifiers specify where the external DTD file is located and how the XML processor should retrieve it. The SYSTEM identifier points directly to a private or local URI, while the PUBLIC identifier references a widely recognized, standardized identifier that can be resolved via an XML catalog, accompanied by a fallback URI. Understanding the distinction between these two mechanisms is essential for writing portable, standard-compliant XML documents.

The SYSTEM Identifier

The SYSTEM identifier is used when an external DTD is intended for private use, internal systems, or hosted at a specific, accessible location. It specifies a direct Uniform Resource Identifier (URI)—such as a local file path or a URL—where the XML parser can locate the DTD file.

Syntax:

<!DOCTYPE root-element SYSTEM "URI">

Example:

<!DOCTYPE note SYSTEM "http://www.example.com/dtd/note.dtd">

or locally:

<!DOCTYPE note SYSTEM "note.dtd">

When an XML parser encounters a SYSTEM declaration, it attempts to fetch the DTD directly from the provided URI. If the network is down or the file path is incorrect, parsing will fail if validation is required.


The PUBLIC Identifier

The PUBLIC identifier is intended for standardized, widely shared DTDs (such as XHTML, MathML, or DocBook). It assigns a globally unique name—called a Formal Public Identifier (FPI)—to the DTD. Because an FPI is a name rather than an address, a PUBLIC declaration also requires a secondary system literal (a backup URI) in case the parser cannot resolve the public name.

Syntax:

<!DOCTYPE root-element PUBLIC "Public_Identifier" "Fallback_URI">

Example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

When an XML processor encounters a PUBLIC identifier, it first checks an internal registry or an XML catalog to see if a local copy of the DTD mapped to that public name already exists. If found, the parser uses the local copy, saving network bandwidth and speeding up processing. If the public identifier cannot be resolved, the parser falls back to the system URI provided at the end of the declaration.


Key Differences

When to Use Which

Use SYSTEM when working with custom schemas internal to an application, organization, or environment where the exact path or URL to the DTD is predictable.

Use PUBLIC when referencing standard schemas developed by standards bodies (like the W3C or OASIS) so consumers of your XML can resolve the schema locally without relying strictly on external network calls.