XSD Schema Element

The root element of every XML Schema is the <schema> element.

The <schema> Element:

Syntax:




...
...

The <schema> Element Attributes:

Some attributes can be included in the <schema> element.

Example: Schema declaration:




...
...

Explanation:

  • The xmlns:xs=”http://www.w3.org/2001/XMLSchema” fragment is used to specify that:
  • the elements and data types used in the schema come from the “http://www.w3.org/2001/XMLSchema” namespace.
  • the elements and data types that come from the “http://www.w3.org/2001/XMLSchema” namespace should be prefixed with xs.
  • The targetNamespace=”https://www.codesjava.com” fragment is used here to specify that the elements defined by the schema (note, to, from, heading, and body) come from the “https://www.codesjava.com” namespace.
  • The xmlns=”https://www.w3schools.blog” fragment is used here to specify that the default namespace is “https://www.w3schools.blog”.
  • The elementFormDefault= “qualified” fragment is used here to specify that any elements used by the XML instance document which were declared in this schema must be namespace-qualified.

Referencing a Schema in an XML Document:

A reference to an XML Schema is there for an XML document.

Example:





Rose
Chris
Message
Meeting on Monday at 10 AM.

Explanation:

  • The xmlns=”https://www.w3schools.blog” fragment is used here to specify that the default namespace is “https://www.w3schools.blog”, thus indicating the schema-validator that all the elements used in this XML document are declared in the “https://www.w3schools.blog” namespace.
  • We can use the schemaLocation attribute after the availability of the XML Schema Instance namespace xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”.
  • There are two values in this attribute, that are separated by a space. The namespace to use is defined by the first value of the attribute, while the location of the XML schema to use for that namespace is defined by the second value of the attribute, i.e., xsi:schemaLocation=”https://www.w3schools.blog note.xsd”.
Please follow and like us:
Content Protection by DMCA.com