subject: Xml Schema Design: Best Practices [print this page] What is an XML Schema? An XML schema is an approach to describe an XML document containing data and other elements by providing specifications that are beyond to XML itself. A typical XML schema contains rules the elements should adhere to, the data type, its attributes, constraints and much more. Various languages such as Document Definition Type, Relax NG, XML Schema, Name Space Routing Language, Document Schema Definition Language, Schematron, SGML contribute to the design of XML schema on an XML editor.
XML design is based on two main processes namely XML coding that involves the task of syntactic aptness followed by validation which is done by the parser specific to the language the design uses. The valid document that complies to the defined schema is said to be a valid instance of the schema. The design of a schema if approached conventionally is a time consuming process, hence several best practices are widely used in this aspect which are explained below.
1) The default namespace in a schema can be either "XMLschema" or "targetNamespace" depending on the designer's personal preference. In case of absence of default namespace, the above namespaces are used to explicitly qualify references and components.
2) By creating two identical copies of schemas which differ from each other in the value of elementFormDefault with one set to "qualified" and the other set to "unqualified", the designer will be able to hide/localize or expose the namespaces based on the functionality, during exports and imports of schemas. Avoiding global declaration of elements and attributes is preferred so as to make elementFormDefault act as a switch.
3) "Russian Doll design" is used where there is a need to minimize size and component coupling, Salami Slice design to accommodate document author's element substitution and Venetial Blind design for easy namespace switching and reuse of the components.
4) The schema component must be easier to identify by its id specification, i.e, the id value should be long enough to include types, elements and attributes.
5) Decision to binding the schema components to the namespace or binding a type reference to an implementation should be postponed.
6)Creating extensible schemas gives much needed flexibility to switch to older schemas during implementation.
7)Awareness of limitations on data types is essential while designing the schema.
8)XML editor with XSLT or Schmeatron is a good way to express business rules not handled by XML Schemas and some other languages.