Search code examples
xmlxsdterminology

What is the difference between a "Processing Directive" and a "Declarative Statement" in XML?


I was just reading this XML Syntax tutorial, and found the definitions of "Processing Directives" (<? ... ?>) and "Declarative Statements" (<! ... >) a little bit foggy. The gist that I get from reading that page is that both of them are ways of the documenting telling the document processor how to do so.

For example, here's a common piece of code that I think many will be familiar with:

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

As far as I can see, these are both instructions on how to process the document. So what's the difference?


Solution

  • Some people when they write tutorials try to be helpful and invent their own terminology, in the hope that people will find it easier to understand than the language of the spec itself. The author of this particular tutorial seems to have gone overboard in this respect. Neither of these terms are official XML terms.

    The first thing in your example is an XML declaration. It tells the XML parser what version of XML you are using, and what the character encoding of your document is.

    The second thing in your example is a DOCTYPE declaration. It tells the XML parser what XML vocabulary you are using (in this case, the XHTML vocabulary), which gives the parser the opportunity to check that you are using the vocabulary correctly (i.e. that your document is valid against the referenced DTD.)