ANY

The second part of this rule (saying that the child element types must have been declared) is not really necessary, since we already said that in the paragraph at the beginning of this list. ANY means exactly what it sounds like it means; the element can contain any old thing in any old order, as long as it doesn't break any of the other rules of XML.

Should ANY Ever Be Used?

Back when we were working through the design of XML, I couldn't see any excuse for having ANY, and voted against it. I lost that vote, and that was probably a good thing, because I have since learned of a very useful way to use ANY. Suppose you're given an existing well-formed XML document and you want to build a DTD for it. One way to do this is as follows:

  1. Make a list of all the element types that actually appear in the document, and build a simple DTD which declares each and every one of them as ANY. Now you've got a DTD (not a very useful one) and a valid document.
  2. Pick one of the elements, and work out how it's actually used in the document. Design a rule, and replace the ANY declaration with an EMPTY or Mixed or Element content declaration. This, of course, is the tricky part, particularly in a large document.
  3. Repeat step 2, working through the elements one by one, until you have a useful DTD.

Back-link to spec

Copyright © 1998, Tim Bray. All rights reserved.