What is MIME type "text/x-dtd"?

A MIME type is a string that tells browsers and other tools how to handle a particular kind of file.

The MIME type text/x-dtd is used for files that define the structure of XML documents. It is a plain text format, meaning it is easy to read and edit.

Files of this type specify which elements and attributes can be used in an XML file. Developers use these definitions to ensure that XML data follows a consistent set of rules and to validate the document's structure. The XML Document Type Definition is stored in files commonly ending with the extension DTD.

Further details can be found on the W3C XML Specification.

Associated file extensions

Usage Examples

HTTP Header

When serving content with this MIME type, set the Content-Type header:


    Content-Type: text/x-dtd    
  

HTML

In HTML, you can specify the MIME type in various elements:


    <a href="file.dat" type="text/x-dtd">Download file</a>    
  

Server-side (Node.js)

Setting the Content-Type header in Node.js:


    const http = require('http');    
    
    http.createServer((req, res) => {    
      res.setHeader('Content-Type', 'text/x-dtd');    
      res.end('Content here');    
    }).listen(3000);    
  

Associated file extensions

FAQs

Is text/x-dtd the official MIME type for DTD files?

No, the officially registered IANA media type is actually application/xml-dtd. However, text/x-dtd is a very common non-standard convention (indicated by the x- prefix) used by many legacy web servers and applications. Because DTD files are human-readable, they are also frequently served simply as text/plain.

How do I configure Apache to serve .dtd files correctly?

You can define the MIME type in your .htaccess file or main configuration using the AddType directive. Add the line AddType text/x-dtd .dtd to ensure Apache sends the correct Content-Type header. This ensures that browsers and XML parsers recognize the file as a Document Type Definition.

Why does my browser download the .dtd file instead of displaying it?

This usually happens if the web server is misconfigured and serves the file as application/octet-stream (binary data) instead of a text type. To fix this, ensure your server is configured to associate the .dtd extension with text/x-dtd, application/xml-dtd, or text/plain. Once corrected, the browser will render the text directly in the window.

How do I add text/x-dtd support to Microsoft IIS?

IIS does not serve unknown file extensions by default, often resulting in a 404 error. You must manually add a MIME Map in the IIS Manager: set the file name extension to .dtd and the MIME type to text/x-dtd. This explicitly tells IIS that it is safe to serve these files to clients.

Are there security risks associated with parsing DTD files?

Yes, DTDs are the vector for XML External Entity (XXE) attacks. If an XML parser is configured to allow external entities defined in a DTD, attackers can potentially read local system files or cause Denial of Service (DoS) via recursive entity expansion (the "Billion Laughs" attack). Developers should disable external entity resolution in their XML parsers unless absolutely necessary.

What is the difference between a DTD and an XSD?

A DTD (served as text/x-dtd) uses a unique, compact syntax to define XML structure, whereas an XSD (XML Schema Definition) is written in XML itself. XSDs are generally more powerful, supporting data types (like integers or dates) and namespaces, which DTDs do not support. Modern applications often prefer XSD, though DTDs remain common for legacy systems.

General FAQ

What is a MIME type?

A MIME (Multipurpose Internet Mail Extensions) type is a standard that indicates the nature and format of a document, file, or assortment of bytes. MIME types are defined and standardized in IETF's RFC 6838.

MIME types are important because they help browsers and servers understand how to process a file. When a browser receives a file from a server, it uses the MIME type to determine how to display or handle the content, whether it's an image to display, a PDF to open in a viewer, or a video to play.

MIME types consist of a type and a subtype, separated by a slash (e.g., text/html, image/jpeg, application/pdf). Some MIME types also include optional parameters.

How do I find the MIME type for a file?

You can check the file extension or use a file identification tool such as file --mime-type on the command line. Many programming languages also provide libraries to detect MIME types.

Why are multiple MIME types listed for one extension?

Different applications and historical conventions may use alternative MIME identifiers for the same kind of file. Showing them all helps ensure compatibility across systems.