XML Standalone Voodoo

The XML standalone declaration should always be last. The encoding declaration Second and the version info First.

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> GOOD
<?xml version="1.0" standalone="yes" encoding="UTF-8" ?> BAD

See the XML Prolog and document type declaration format for clarity on this

[22]  prolog ::= XMLDecl? Misc* (doctypedecl Misc*)?
[23]  XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'
[24]  VersionInfo ::= S 'version' Eq (' VersionNum ' | " VersionNum ")
[25]  Eq ::= S? '=' S?
[26]  VersionNum ::= ([a-zA-Z0-9_.:] | '-')+
[27]  Misc ::= CommentPIS

“In a standalone document declaration, the value “yes” indicates that there are no markup declarations external to the document entity (either in the DTD external subset, or in an external parameter entity referenced from the internal subset) which affect the information passed from the XML processor to the application. The value “no” indicates that there are or may be such external markup declarations. Note that the standalone document declaration only denotes the presence of external declarations; the presence, in a document, of references to external entities, when those entities are internally declared, does not change its standalone status.

If there are no external markup declarations, the standalone document declaration has no meaning. If there are external markup declarations but there is no standalone document declaration, the value “no” is assumed.

Any XML document for which standalone="no" holds can be converted algorithmically to a standalone document, which may be desirable for some network delivery applications.

Validity Constraint: Standalone Document Declaration
The standalone document declaration must have the value “no” if any external markup declarations contain declarations of:

  • attributes with default values, if elements to which these attributes apply appear in the document without specifications of values for these attributes, or
  • entities (other than amp, lt, gt, apos, quot), if references to those entities appear in the document, or
  • attributes with values subject to normalization, where the attribute appears in the document with a value which will change as a result of normalization, or
  • element types with element content, if white space occurs directly within any instance of those types.”

About James McParlane

CTO Massive Interactive. Ex Computer Whiz Kid - Now Grumpy Old Guru.
This entry was posted in Rants, XML. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s