Vocabularies
- Last UpdatedJan 27, 2023
- 1 minute read
In XML the tags are not predefined, an application must define its own tags. A set of tags used by a specific application is often referred to as an "vocabulary". When describing a vocabulary you typically state:
-
What elements and attributes are accepted by the application
-
In what order the elements must be given
-
If elements/attributes are required or optional
-
Data types of attributes.
-
Minimum and/or maximum value attributes
-
Default values of attributes
The vocabulary of an application can be described in a separate document. There are several formats for describing an XML vocabulary of which the most common ones are:
-
DTD. Stands for "Document Type Definition". This is one of the first formats that were created for defining vocabularies.
-
XML Schema. This format is developed by the world wide web consortium, W3C.
-
XML Data Reduced. This is a subset of XML Schema.
If an XML document should be validated against a special vocabulary it must have some kind of reference to this vocabulary. You will find this reference in the root element of the XML document, in this example an XML schema:
<Ship xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="CurvedHull.xsd">
...
</Ship>
Here the root element "Ship" has two special attributes. The first one, called "xmlns:xsi" is actually a reference to the definition of XML Schema language itself. The second attribute, "xsi:noNamespaceSchemaLocation", points out the schema file defining the vocabulary that this document applies to.