What is the meaning of DOCTYPE in xml file?
Asked Answered
L

2

5

In hibernate we use configuration and mapping xml files. In xml the first line will be version and then we specify DOCTYPE DTD line. Example:

<!DOCTYPE hibernate-mapping PUBLIC  "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

Can anybody please explain what is the meaning of this? I know that DTD is document type definition which is like defining grammar for the xml.

I want to know the attributes in this statement.

Lizzettelizzie answered 27/5, 2011 at 11:21 Comment(0)
S
6

The line you refer to is the document type declaration.

It is documented in the W3C's XML Recommendation here: http://www.w3.org/TR/xml/#dt-doctype

It specifies a DTD that is to be used when processing the document. Two mechanisms are available for specifying this

  1. an optional PUBLIC identifier (rare these days) which is, in your example, " -//Hibernate/Hibernate Mapping DTD 3.0//EN". The mechanism by which this is resolved to a DTD resource is application-specific.

  2. A SYSTEM identifier, which in your example is "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd". This is typically interpreted as a URL from where the DTD can be retrieved.

Scenography answered 27/5, 2011 at 11:28 Comment(0)
R
2

A Doctype describes which DTD the XML file follows.

This:

  1. Describes what elements are allowed inside what other elements (for the purpose of validation)
  2. Describes what named character references are available (beyond the 5 XML built-ins of &amp;, &lt;, &gt;, &apos; and &quot;).
Rori answered 27/5, 2011 at 13:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.