Production Count

This metric asks the question “How complex is this schema?” (or DTD).

For a DTD, count the number of “<!” strings, substract the number of “<!–” strings, subtract the number of “<!ENTITY” strings and add the number of “<!ENTITY %” strings. This gives a count of the element, attlist, notation, marked sections and parameter entities declarations.

For an XML Schema, count the number of top-level non-comment elements, then add the number of elements declared locally and the number of elements that have attributes declared locally.

I recently used a variant on this metric on behalf of a client for a large project. The XML schema consultant on the project had assembled a schema based on industry standards and best practises; the XML programming team leader was concerned that this introduced many unnecessary elements and had mad an alternative, specific, minimal schema. Using this metric allowed us to say that one schema was at least five times as complex as the other, and circumvented the suspicion that there was just a personality difference involved. But what does “five times” mean? Well, all it needed to mean in this case was that the schemas were substantially different in some sense.