What is a schema?
How do we know which elements and attributes are in a namespace? An XML language will have public-facing documentation if it’s an open standard designed for the exchange of information. For example, we looked at the documentation for Beer XML: An Open XML Standard. That documentation tells you which elements are required and optional in that language.
XML languages can go one step further and provide a schema that sets out the rules of the language.
A schema sets out the rules of the XML language in a machine-readable way.
If you associate your XML file with that schema, Oxygen will read the schema and ensure that your document follows the rules of the XML language. A well written schema will provide error messages and prompts that help you figure out what is required next by the namespace in which you are working.
What rules does a schema set out?
The schema sets out the same rules as those set out by the documentation … in a machine-readable way.
- The elements that are required in a document encoded in a particular XML language.
- Where in the XML hierarchy those elements are required (i.e., as children of a parent element) and where they are prohibited.
- How many instance of the element can you have at that point in the XML hierarchy (zero, one, or more than one).
- What sibling elements are required.
- What attributes are required and/or allowed on each element.
- What values are allowed on each attribute (if the values are constrained).
- Whether or not an attribute can have multiple values.
- What elements can have text nodes.
Further Reading:
- Introduction to XML Schema Tutorial at W3 Schools: https://www.w3schools.com/xml/schema_intro.asp