Friday, February 15, 2013

What does the 'standalone' directive mean in an XML document?

Markup declarations can affect the content of the document, as passed from an XML processor to an application; examples are attribute defaults and entity declarations. The standalone document declaration, which may appear as a component of the XML declaration, signals whether or not there are such declarations which appear external to the document entity or in parameter entities. [Definition: An external markup declaration is defined as a markup declaration occurring in the external subset or in a parameter entity (external or internal, the latter being included because non-validating processors are not required to read them).]
http://www.w3.org/TR/xml/#sec-rmd


standalone describes if the current XML document depends on an external markup declaration.
W3C describes its purpose in "Extensible Markup Language (XML) 1.0 (Fifth Edition)":
That might help: http://www.stylusstudio.com/w3c/xml11/sec-rmd.htm
 
My reading of the spec is that the standalone declaration is a way of telling the parser to ignore a DTD if one is provided. Not all parsers will respect this, but standards-compliant validating parsers (like a browser) should.
As an example, consider the humble tag. If you look at the XHTML 1.0 DTD, you see a markup declaration telling the parser that tags must be EMPTY, and must contain src and alt attributes. When a browser is going through an XHTML 1.0 document and finds an tag, it should notice that the DTD requires these src and alt attributes and add them in if not present. It will also self-close the tag since it is supposed to be EMPTY. This is what the spec means by "affecting the content of the document."
Theoretically you can use the standalone declaration to tell the parser to ignore these rules in the DTD. Whether or not your parser actually does this is another question.
Note that if you do not specify a DTD, then the standalone declaration "has no meaning," according to the spec.
 

No comments: