


Section 4: Developers

Q 4.3: What are these terms DTDless, valid, and well-formed?

Well-formed means just syntactically correct; valid means it conforms to a DTD or Schema.

XML lets you use a Schema or Document Type Definition (DTD) to describe the markup (elements and other constructs) available in any specific type of document. However, the design and construction of Schemas and DTDs can be complex and non-trivial, so XML also lets you work without one. DTDless operation means you can invent markup without having to define it formally, provided you stick to the well-formedness rules of XML syntax.



  • The <img> element is declared (in the [SGML] DTDs for HTML) as EMPTY, so it doesn't have an end-tag (there is no such thing as </img>);

  • Many other HTML elements (such as <para>) allow you to omit the end-tag for brevity.

  • If an XML processor reads an HTML file without knowing this (because it isn't using a DTD), and it encounters an <img> or a <para> (or any other start-tag), it would have no way to know whether or not to expect an end-tag. This makes it impossible to know if the rest of the file is correct or not, because it has now no evidence of whether it is inside an element or if it has finished with it.




David Brownell writes:



Richard Lander writes:


<!DOCTYPE example [ 
<!ENTITY mdash " — "> 
<example>Hindsight&mdash;a wonderful thing.</example> 

So…here are the rules:

Peter Flynn writes:

Well-formed XML


  • All attribute values must be in quotes. The single-quote character (the apostrophe) may be used if the value contains a double-quote character, and vice versa. If you need isolated quotes as data as well, you can use &apos; or &quot;. Do not under any circumstances use the automated typographic (‘curly’) inverted commas substituted by some wordprocessors for quoting attribute values — keep them for the values themselves (eg surname="O’Flynn" rather than surname="O'Flynn");

  • Any EMPTY elements (eg those with no end-tag like HTML's <img>, <hr>, and <br> and others) must either end with /> or they must look like non-EMPTY elements by having a real end-tag (but no content). Example: <br> would become either <br/> or <br> </br> (with nothing in between).

  • There must not be any isolated markup-start characters (< or &) in your text data. They must be given as &lt; and &amp; respectively, and the sequence ]] > may only occur as the end of a CDATA marked section: if you are using it for any other purpose it must be given as ]] &gt;.


  • Comment declarations <!-- like this --> can only appear between or inside elements, or in character data content, not inside a start-tag or end-tag. The sequence -- (hyphen hyphen) must not occur by itself in the text of a comment because it can only be used as the comment close delimiter (followed by the >);


  • XML files with no DTD are considered to have &lt;, &gt;, &apos;, &quot;, and &amp; predefined and thus available for use. With a DTD, all character entities used must be declared, including these five.

Peter Flynn writes:

Valid XML

Valid XML files are well-formed files which have a Document Type Definition (DTD) or Schema and which conform to it. They must already be well-formed, so all the rules above apply.

A valid file begins with a Document Type Declaration specifying a DTD, or code specifying a W3C Schema. It may have an optional XML Declaration prepended.

<?xml version="1.0"?> 
<!DOCTYPE advert SYSTEM ""> 


Peter Flynn writes:



It is possible (many people would say preferable) to supply a Formal Public Identifier with the PUBLIC keyword, and use an XML Catalog to dereference it, but the Specification mandates a SYSTEM Identifier so this must still be supplied after the PUBLIC identifier: no further keyword is needed. A PUBLIC identifier constitutes a claim to ownership only of the identifier, not to the DTD itself (although ion many cases that is implied).

   "+//Silmaril//DTD Foo Corp Advertisements//EN"

