Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Why use XML Schema?


May 28, 2021 XML Schema


Table of contents


Why use XML Schemas?

Since XML Schemas does the same thing as DTD (document type definition), why use XML Schemas?


XML Schema is more powerful than DTD.


XML Schema supports data types

One of XML Schema's most important capabilities is support for data types.

By supporting data types:

  • It is easier to describe the allowed document content
  • It is easier to verify the correctness of your data
  • It is easier to work with data from the database
  • Data constraints can be defined more easily (data facets)
  • Easier definition of data models (or data formats)
  • It is easier to transform data between different data types

Editor's note: Data constraints, or facets, are a term in the XML Schema prototype that can be translated as a Chinese face" to constrain the permissible values of the data type.


XML Schema uses XML syntax

Another important feature about XML Schema is that they are written by XML.

Writing XML Schema by XML has many benefits:

  • You don't have to learn a new language
  • You can use the XML editor to edit Schema files
  • You can use the XML parser to parse Schema files
  • Schema can be processed through XML DOM
  • Schema can be converted via XSLT

XML Schema protects data communications

When data is sent from the sender to the recipient, the point is that both parties should have the same "expectations" for the content.

With XML Schema, the sender can describe the data in a way that the recipient can understand.

One data, such as "03-11-2004", was interpreted in some countries as 3 November and in others as 11 March.

However, an XML element with a data type, such as: .lt;date type="date";2004-03-11</date=gt;, ensures a consistent understanding of the content because the data type "date" of the XML requires a format of "YYYYY-MM-DD".


XML Schema is scalable

XML Schema is scalable because they are written by XML.

With the scalable Schema definition, you can:

  • Reuse your Schema in other Schemas
  • Create your own data types derived from standard types
  • Reference multiple Schemas in the same document

Good form is not enough

We refer to documents that conform to the XML syntax as well-formed XML documents, such as:

  • It must begin with an XML declaration
  • It must have a unique root element
  • The start label must match the end label
  • Elements are case sensitive
  • All elements must be closed
  • All elements must be nested correctly
  • Entities must be used for special characters

Even if the documents are in good form, there is no guarantee that they will not contain errors, and that these errors can have serious consequences.

Consider the following scenario: You ordered 5 laser printers instead of 5. With XML Schema, most of these errors are caught by your validation software.

In the next section, we'll start learning to use XML Schema.