MTI TEK
  • Home
  • About
  • LLMs
  • Docker
  • Kubernetes
  • Java
  • All Resources
XML | Schema
  1. Introduction
  2. Built-in Data Types
  3. Custom Data Types
  4. Element Declarations
  5. Schema Validation
  6. Elements References
  7. Attributes References

  1. Introduction
    An XML Schema defines the syntactic and semantic structure that XML documents, which reference the XML Schema, must follow in order to be valid. It provides a powerful way to define the structure, content, and semantics of XML documents, including data types, element relationships, and constraints.

    XML Schema is also known as XML Schema Definition (XSD). While "XML Schema" refers to the broader concept and specification, "XSD" specifically refers to the file format and extension used for schema files. XML Schema is written in XML itself.

    For example, the following XML document:
    <?xml version="1.0"?>
    <book>
        <title>XML</title>
        <isbn>123</isbn>
    </book>
    
    Can be validated against the following XML Schema:
    <?xml version="1.0"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:element name="book">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="title" type="xs:string" />
                    <xs:element name="isbn" type="xs:string" />
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    </xs:schema>
    
    Note: The XML Schema namespace "http://www.w3.org/2001/XMLSchema" is the standard namespace for XML Schema definitions. The prefix "xs" is conventional but not required - you can use any prefix. To perform actual validation, you need an XML parser or validator that supports XML Schema validation (such as those found in programming languages like Java or Python).

    To declare that the XML document must conform to an XML Schema, the XML Schema must first define a namespace, which the XML document must then reference in order to be validated against the schema:

    • The XML Schema uses the "targetNamespace" attribute to specify a namespace ("http://www.mtitek.com/ns/books") that can be used by XML documents.
      <?xml version="1.0"?>
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
          xmlns="http://www.mtitek.com/ns/books"
          targetNamespace="http://www.mtitek.com/ns/books"
          elementFormDefault="qualified">
          ...
      </xs:schema>
      
      The XML Schema can also define a namespace (which may be the same as the one specified for the "targetNamespace" attribute). But this one is used only within the schema to identify schema elements.

      Note: The "xmlns" attribute without a prefix declares the default namespace for the schema document itself, making it easier to reference elements defined in the target namespace without prefixes.

    • The XML document must define a namespace whose value must match the "targetNamespace" attribute in the XML Schema. The XML document must also define the namespace "http://www.w3.org/2001/XMLSchema-instance", which is used to specify the location of the XML Schema (via the "schemaLocation" attribute). The prefix "xsi" is standard for referring to the schema, but any prefix name will work correctly.

      The value of the "schemaLocation" attribute consists of two parts (separated by a space): The first part is the namespace (must match the value of "targetNamespace" in the schema), and the second part is the location of the XML Schema file.

      The schema location can be relative to the XML document (example: "booksSchemaFile.xsd"), or absolute, by specifying an explicit path to a local resource (hard drive: "file:///C:/xs/booksSchemaFile.xsd") or a remote resource (intranet or internet: "http://www.mtitek.com/xs/booksSchemaFile.xsd").
      <?xml version="1.0"?>
      <book
          xmlns="http://www.mtitek.com/ns/books"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://www.mtitek.com/ns/books booksSchemaFile.xsd">
          ...
      </book>
      
      Note: For XML documents that don't use namespaces, you can use "xsi:noNamespaceSchemaLocation" instead of "xsi:schemaLocation". This attribute takes only the schema location (no namespace part).

    In an XML document, elements (and also attributes) can be qualified or unqualified. An element (or attribute) is qualified if it has an associated namespace, either explicitly with a prefix or implicitly with a default namespace.

    You can specify whether elements should be qualified using the "elementFormDefault" attribute in the schema:
    • If this attribute is set to "qualified", then all elements in the XML document must be namespace-qualified (either with a prefix or through a default namespace declaration). This means every element, including child elements, must belong to the target namespace.
    • If this attribute is omitted or set to "unqualified", then only the root element needs to be qualified, and child elements should not have namespace qualification.

    You can also specify whether attributes should be qualified using the "attributeFormDefault" attribute in the schema:
    • If this attribute is set to "qualified", then attributes must be qualified.
    • If this attribute is omitted or set to "unqualified", then attributes must be unqualified.

    If elements (and attributes) are required to be qualified, then XML validation will fail if they do not have an associated namespace.

    On the other hand, if they are required to be unqualified, then validation will fail if they do have a namespace (including a default namespace).

    Note: Most schemas leave attributes unqualified unless there's a specific need for qualification.

    The following is an example of an XML Schema and an XML document that both use these attributes:
    <?xml version="1.0"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns="http://www.mtitek.com/ns/books"
        targetNamespace="http://www.mtitek.com/ns/books"
        elementFormDefault="qualified"
        attributeFormDefault="qualified">
        <xs:element name="book">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="title" type="xs:string" />
                    <xs:element name="isbn" type="xs:string" />
                </xs:sequence>
    
                <xs:attribute name="edition" type="xs:positiveInteger" />
            </xs:complexType>
        </xs:element>
    </xs:schema>
    
    <?xml version="1.0"?>
    <b:book xmlns:b="http://www.mtitek.com/ns/books"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.mtitek.com/ns/books booksSchemaFile.xsd"
        b:edition="1">
        <b:title>XML</b:title>
        <b:isbn>123</b:isbn>
    </b:book>
    
  2. Built-in Data Types
    XML Schema provides a set of built-in data types that can be classified into primitive types and derived types.

    All types are derived from the root type "anyType", which is the base for both simple and complex types.

    Simple types are further derived from "anySimpleType", which is the root of all simple types.

    Built-in types can be categorized as:
    • Primitive types:
      Basic types that are not derived from other simple types (e.g., string, boolean, decimal, float, double, duration, dateTime, time, date, etc.).

    • Derived types:
      Types that are derived from primitive types or other derived types (e.g., integer from decimal, normalizedString from string, etc.).

    Note: Derived types inherit the constraints of their base types and can add additional restrictions through facets (such as pattern, length, minInclusive, etc.).

    Built-in types references:
    • Any Simple Type:
      This is the base type for all simple types and cannot contain child elements or attributes.
      All simple types derive from this type.
      anySimpleType
      
    • Boolean:
      Valid values: true, false, 1 (true), 0 (false)
      boolean
      
    • Numeric:
      Numeric types form a derivation hierarchy.
      For example:
      - decimal → integer → nonNegativeInteger → positiveInteger
      - decimal → integer → long → int → short → byte.
      Fixed-size integer types:
      unsignedByte (0 to 255)
      byte (-128 to 127)
      unsignedShort (0 to 65,535)
      short (-32,768 to 32,767)
      unsignedInt (0 to 4,294,967,295)
      int (-2,147,483,648 to 2,147,483,647)
      unsignedLong (0 to 18,446,744,073,709,551,615)
      long (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)
      
      Primitive types:
      decimal (decimal numbers with arbitrary precision)
      float (32-bit floating point)
      double (64-bit floating point)
      
      Derived integer types:
      integer (arbitrary precision integers, derived from decimal)
      positiveInteger (1, 2, 3, ... - derived from nonNegativeInteger)
      nonNegativeInteger (0, 1, 2, 3, ... - derived from integer)
      negativeInteger (..., -3, -2, -1 - derived from nonPositiveInteger)
      nonPositiveInteger (..., -3, -2, -1, 0 - derived from integer)
      
    • Dates and Times:
      Date/time types can include timezone information (e.g., 2025-06-25T08:25:30-05:00).
      Duration follows ISO 8601 format where P indicates period, T separates date and time components.
      Primitive types:
      date (YYYY-MM-DD, e.g., 2025-06-25)
      dateTime (YYYY-MM-DDTHH:MM:SS, e.g., 2025-06-25T14:30:00)
      time (HH:MM:SS, e.g., 14:30:00)
      duration (PnYnMnDTnHnMnS, e.g., P1Y2M3DT4H5M6S = 1 year, 2 months, 3 days, 4 hours, 5 minutes, 6 seconds)
      
      Derived date/time types:
      gDay (---DD, e.g., ---15)
      gMonth (--MM, e.g., --06)
      gMonthDay (--MM-DD, e.g., --06-25)
      gYear (YYYY, e.g., 2025)
      gYearMonth (YYYY-MM, e.g., 2025-06)
      
    • Strings and Text:
      String types form a derivation hierarchy: string → normalizedString → token.
      "Normalized whitespace" means tabs and newlines are converted to spaces.
      "Token" additionally removes leading/trailing whitespace and collapses multiple consecutive spaces.
      Basic string types:
      string (any string - primitive type)
      normalizedString (string with tabs/newlines converted to spaces)
      token (normalized string with no leading/trailing whitespace and collapsed internal spaces)
      
      Name types (derived from token):
      Name (valid XML name)
      NCName (non-colonized name - XML name without namespace prefix)
      QName (qualified name with optional namespace prefix)
      
      Token types:
      NMTOKEN (name token - valid XML name token)
      NMTOKENS (space-separated list of NMTOKENs)
      language (language code like "en-US", derived from token)
      
      XML-specific types:
      ID (unique identifier within document)
      IDREF (reference to an ID)
      IDREFS (space-separated list of IDREFs)
      ENTITY (reference to an unparsed entity)
      ENTITIES (space-separated list of entities)
      NOTATION (reference to a notation)
      
      Other types:
      anyURI (URI reference - primitive type)
      base64Binary (base64-encoded binary data - primitive type)
      hexBinary (hexadecimal-encoded binary data - primitive type)
      
  3. Custom Data Types
    You can create custom simple types using three main approaches: restrictions, lists, and unions. Custom types allow you to define specific validation rules and constraints beyond the built-in types.

    • Restrictions:
      Create new types by applying constraints (called facets) to existing types. Multiple facets can be combined to create precise validation rules.

      Common facets: pattern, length, minLength, maxLength, enumeration, minInclusive, maxInclusive, minExclusive, maxExclusive, totalDigits, fractionDigits, whiteSpace.
      <!-- Simple pattern restriction -->
      <xs:simpleType name="restrictedString">
          <xs:restriction base="xs:string">
              <xs:pattern value="[A-Z]{3}" />
          </xs:restriction>
      </xs:simpleType>
      
      <!-- Simple pattern restriction combined with other restrictions -->
      <xs:simpleType name="restrictedStringWithLength">
          <xs:restriction base="xs:string">
              <xs:pattern value="[A-Z]*" />
              <xs:length value="3" />
          </xs:restriction>
      </xs:simpleType>
      
      <!-- Numeric restriction with range -->
      <xs:simpleType name="restrictedNumeric">
          <xs:restriction base="xs:decimal">
              <xs:minInclusive value="0" />
              <xs:maxInclusive value="6" />
              <xs:fractionDigits value="2" />
          </xs:restriction>
      </xs:simpleType>
      
      <!-- Enumeration restriction -->
      <xs:simpleType name="restrictedEnumeration">
          <xs:restriction base="xs:string">
              <xs:enumeration value="true" />
              <xs:enumeration value="false" />
          </xs:restriction>
      </xs:simpleType>
      
    • Lists:
      Create types that contain space-separated sequences of values. All items in the list must be of the same type (the itemType). List items are separated by whitespace (spaces, tabs, newlines).

      Note: The itemType itself cannot be a list, union, or any type that contains lists or unions.
      <!-- Simple list -->
      <xs:simpleType name="listOfStrings">
          <xs:list itemType="xs:string" />
      </xs:simpleType>
      
    • Unions:
      Create types that can accept values from multiple different types. During validation, the first type in the memberTypes list that successfully validates the value is used.
      <!-- Simple union -->
      <xs:simpleType name="stringOrInt">
          <xs:union memberTypes="xs:string xs:int" />
      </xs:simpleType>
      
      Note: Validation uses the first matching type. For example the example above "xs:string xs:int", the string "123" will be treated as a string, not an integer.

    The following is an example of an XML Schema and an XML document that use the above custom data types:
    <?xml version="1.0"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns="http://www.mtitek.com/ns/customDataTypes"
        targetNamespace="http://www.mtitek.com/ns/customDataTypes"
        elementFormDefault="qualified">
        <xs:element name="customData">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="info" type="xs:string" />
    
                    <xs:element name="restriction" type="restrictedString" />
                    <xs:element name="list" type="listOfStrings" />
                    <xs:element name="union" type="stringOrInt" />
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    
        <!-- Restriction example -->
        <xs:simpleType name="restrictedString">
            <xs:restriction base="xs:string">
                <xs:pattern value="[A-Z]{3}" />
            </xs:restriction>
        </xs:simpleType>
    
        <!-- List example -->
        <xs:simpleType name="listOfStrings">
            <xs:list itemType="xs:string" />
        </xs:simpleType>
    
        <!-- Union example -->
        <xs:simpleType name="stringOrInt">
            <xs:union memberTypes="xs:string xs:int" />
        </xs:simpleType>
    </xs:schema>
    
    <?xml version="1.0"?>
    <c:customData xmlns:c="http://www.mtitek.com/ns/customDataTypes"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.mtitek.com/ns/customDataTypes customDataTypesFile.xsd">
        <c:info>Custom Data Types Example</c:info>
    
        <c:restriction>ABC</c:restriction>
        <c:list>X Y Z</c:list>
        <c:union>W</c:union>
    </c:customData>
    
  4. Element Declarations
    An element is declared using the following syntax:
    <xs:element
        id=""                  Unique identifier within the schema
        name=""                The name of the element (required for element declarations)
        type=""                The data type of the element (can be built-in or user-defined)
        minOccurs=""           Minimum number of times the element can occur (default: 1)
        maxOccurs=""           Maximum number of times the element can occur (default: 1, use "unbounded" for unlimited)
        default=""             Default value if element is not present
        fixed=""               Fixed value that the element must have
        nillable=""            Whether the element can have a nil value (xsi:nil="true")
        abstract=""            Whether the element is abstract (cannot appear in instance documents, only substituted)
        substitutionGroup=""   Head element of the substitution group this element belongs to
        form=""                Whether the element is qualified or unqualified (overrides schema default)
        block=""               Prevents certain types of derivation or substitution (values: "extension", "restriction", "substitution", "#all")
        final=""               Prevents derivation of new elements from this element (values: "extension", "restriction", "#all")
    >
        ...
    </xs:element>
    
    Element Scope:
    • Local Elements:
      Declared within complex types, groups, or other local scopes. They have local scope and cannot be referenced using the "ref" attribute from other parts of the schema.
      <xs:complexType name="BookType">
          <xs:sequence>
              <xs:element name="title" type="xs:string" />
              <xs:element name="isbn" type="xs:string" />
          </xs:sequence>
      </xs:complexType>
      
    • Global Elements:
      Declared as direct children of "xs:schema". They can serve as document root elements and can be referenced throughout the schema using the "ref" attribute.
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
          <xs:element name="book" type="BookType" />
          <xs:element name="library">
              <xs:complexType>
                  <xs:sequence>
                      <xs:element ref="book" maxOccurs="unbounded" />
                  </xs:sequence>
              </xs:complexType>
          </xs:element>
      </xs:schema>
      
      Note: When using "ref", you reference an existing global element. You cannot specify "name", "type", or most other attributes on the referencing element; only occurrence constraints ("minOccurs", "maxOccurs"), "id", and annotation elements can be used.

    Element Content Types:
    • Simple Content: Contains only text data, no child elements. This is the most basic element type.
      <xs:element name="title" type="xs:string" />
      
    • Simple Content with Attributes: Contains only text content but can have attributes. Use "simpleContent" with "extension" to add attributes to a simple type.
      <xs:element name="isbn">
          <xs:complexType>
              <xs:simpleContent>
                  <xs:extension base="xs:string">
                      <xs:attribute name="format" type="xs:string" />
                  </xs:extension>
              </xs:simpleContent>
          </xs:complexType>
      </xs:element>
      
      Example:
      <isbn format="ISBN-13">123-0123456789</isbn>
      
    • Complex Content: Contains child elements and/or attributes. This is the most common type for structured data.
      <xs:element name="book">
          <xs:complexType>
              <xs:sequence>
                  <xs:element name="title" type="xs:string" />
                  <xs:element name="isbn" type="xs:string" />
              </xs:sequence>
              <xs:attribute name="edition" type="xs:positiveInteger" />
          </xs:complexType>
      </xs:element>
      
    • Mixed Content: Contains both text and child elements intermixed.
      The 'mixed="true"' attribute allows text content between child elements.
      The order and occurrence of text and elements can vary, but child elements must still follow the defined content model.
      <xs:element name="bookInfo">
          <xs:complexType mixed="true">
              <xs:sequence>
                  <xs:element name="note" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
                  <xs:element name="comment" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
              </xs:sequence>
          </xs:complexType>
      </xs:element>
      
      Examples:
      <bookInfo>Just text with no child elements.</bookInfo>
      
      <bookInfo>
          <note>One note</note>
      </bookInfo>
      
      <bookInfo>
          This is a mixed content
          <note>first note</note>
          more text
          <comment>first comment</comment>
          and more text
          <note>second note</note>
          another text
          <comment>second comment</comment>
          end of content.
      </bookInfo>
      
    • Empty Content: Contains no text content, only attributes. The element can be self-closing or have opening/closing tags with no content between them.
      <xs:element name="bookEdition">
          <xs:complexType>
              <xs:attribute name="edition" type="xs:string" />
          </xs:complexType>
      </xs:element>
      
      Examples:
      <bookEdition />
      
      <bookEdition edition="4th Edition" />
      
    Nillable Elements:
    Elements can be declared as nillable to allow explicit null values using 'xsi:nil="true"'.
    When 'xsi:nil="true"' is specified, the element must be empty (no content) even if the element's type would normally allow content.
    This is different from a missing element or an empty element; it explicitly represents "no value" or "null".
    <xs:element name="isbn" type="xs:string" nillable="true" />
    
    XML documents must declare the XML Schema Instance namespace to use "xsi:nil":
    <book xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <isbn xsi:nil="true" />
    </book>
    
    Default Values:
    Provided when element is missing from the instance document.
    <xs:element name="title" type="xs:string" default="MTI" />
    <xs:element name="isbn" type="xs:string" default="123" />
    
    Fixed Values:
    Element must have exactly this value when present.
    If the element appears with a different value, validation fails.
    <xs:element name="title" type="xs:string" fixed="MTI" />
    <xs:element name="isbn" type="xs:string" fixed="123" />
    
    Note: Default and fixed attributes are mutually exclusive and only apply to elements with simple content (including elements with simple content and attributes).

    Occurrence Constraints:
    Control how many times an element can appear.
    These constraints work within the context of their parent compositor (sequence, choice, all).
    "minOccurs" must be a non-negative integer (0 or greater).
    "maxOccurs" can be a positive integer or "unbounded".
    The value of "minOccurs" cannot be greater than "maxOccurs".
    <xs:element name="title" type="xs:string" /> <!-- Required, exactly once (default) -->
    <xs:element name="title" type="xs:string" minOccurs="1" maxOccurs="1" /> <!-- Required, exactly once (explicit) -->
    <xs:element name="title" type="xs:string" minOccurs="0" /> <!-- Optional, max one -->
    <xs:element name="title" type="xs:string" maxOccurs="unbounded" /> <!-- Required, one or more -->
    <xs:element name="title" type="xs:string" minOccurs="0" maxOccurs="unbounded" /> <!-- Optional, zero or more -->
    <xs:element name="title" type="xs:string" minOccurs="3" maxOccurs="6" /> <!-- Required, between 3 and 6 occurrences -->
    
  5. Schema Validation
    XML Schema validation ensures that XML documents conform to the structure and constraints defined in the schema:
    • Structural Validation:
      • Element and attribute presence and order according to content models.
      • Occurrence constraints (minOccurs, maxOccurs) - correct number of element repetitions.
      • Content model compliance (sequence, choice, all) - proper element ordering and selection.
      • Proper nesting and hierarchy of elements.
      • Compliance with mixed content rules when mixed="true" is specified.

    • Data Type Validation:
      • Value format according to specified data types (e.g., dates, numbers, booleans).
      • Facet constraints (length, pattern, enumeration, etc.).
      • Range constraints (minInclusive, maxInclusive, minExclusive, maxExclusive).
      • Precision constraints for numeric types (totalDigits, fractionDigits).
      • Whitespace handling according to whiteSpace facet (preserve, replace, collapse).

    • Identity Constraints:
      • Key constraints: Ensure uniqueness and existence of specified values (like primary keys in databases).
      • Key reference constraints: Ensure referential integrity (like foreign keys in databases).
      • Unique constraints: Ensure uniqueness without requiring existence.
      • Proper XPath expressions in selector and field elements.

    • Namespace Validation:
      • Proper namespace declarations and scope.
      • Qualified vs. unqualified element/attribute forms matching schema requirements.
      • Target namespace compliance with schema targetNamespace.
      • Correct use of namespace prefixes and default namespaces.
      • Schema location validation and accessibility.

    • Type Derivation Validation:
      • Proper inheritance from base types through extension or restriction.
      • Compliance with restriction rules (derived type must be more restrictive).
      • Valid extension of base types (adding new elements/attributes).
      • Abstract type usage restrictions (cannot be instantiated directly).
      • Final and block attribute enforcement (preventing derivation or substitution).

    Validation Modes:
    • Strict Validation: All elements must be declared in the schema. Undeclared elements cause validation failure.
    • Lax Validation: Undeclared elements are allowed but declared elements must be valid.
    • Skip Validation: No validation is performed on specific elements or their descendants.
  6. Elements References
    • Element Declarations
      • element
        <xs:element
            id=""
            name=""
            type=""
            minOccurs="1" <!-- Control element cardinality -->
            maxOccurs="1" <!-- Control element cardinality (use "unbounded" for unlimited) -->
            nillable="false" <!-- Allows xsi:nil="true" in instance documents -->
            form="unqualified" <!-- "qualified" or "unqualified" (overrides elementFormDefault) -->
            ref=""
            default=""
            block="" <!-- Prevents substitution: "substitution", "extension", "restriction", or "#all" -->
            final="" <!-- Prevents derivation: "extension", "restriction", or "#all" -->
            fixed=""
            substitutionGroup="" <!-- Allows element substitution in valid instances -->
            abstract="false"> <!-- If true, element cannot appear in instance documents (used as base for substitution) -->
        (annotation?, (simpleType | complexType)?, ((unique | key | keyref))*)
        </xs:element>
        
      • any
        Allows any element from specified namespaces to appear.
        <xs:any
            id=""
            namespace="##any" <!-- Controls which namespaces are allowed: ##any, ##other, ##targetNamespace, ##local, or URI list -->
            processContents="strict" <!-- Controls validation level: "strict", "lax", "skip" -->
            minOccurs="1"
            maxOccurs="1">
        (annotation?)
        </xs:any>
        
    • Attribute Declarations
      • attribute
        <xs:attribute
            id=""
            type=""
            name=""
            default=""
            fixed=""
            use="optional" <!-- "required", "optional", or "prohibited" -->
            form="unqualified" <!-- "qualified" or "unqualified" (overrides attributeFormDefault) -->
            ref=""> <!-- References a global attribute declaration -->
        (annotation?, simpleType?)
        </xs:attribute>
        
      • anyAttribute
        Allows any attribute from specified namespaces to appear.
        Typically used at the end of attribute declarations in complex types.
        <xs:anyAttribute
            id=""
            namespace="##any" <!-- Controls which namespaces are allowed: ##any, ##other, ##targetNamespace, ##local, or URI list -->
            processContents="strict"> <!-- Controls validation level: "strict", "lax", "skip" -->
        (annotation?)
        </xs:anyAttribute>
        
      • attributeGroup
        Groups attributes for reuse across multiple complex types.
        Can be defined globally (with name) or referenced (with ref).
        <xs:attributeGroup
            id=""
            name=""
            ref="">
        (annotation?, ((attribute | attributeGroup)*, anyAttribute?))
        </xs:attributeGroup>
        
    • Type Definitions
      • simpleType
        Defines new simple types through restriction, list, or union of existing types.
        Can be global (with name) or local (anonymous).
        <xs:simpleType
            id=""
            name=""
            final=""> <!-- Prevents derivation: "restriction", "list", "union", or "#all" -->
        (annotation?, (restriction | list | union))
        </xs:simpleType>
        
      • complexType
        <xs:complexType
            id=""
            name=""
            abstract="false" <!-- If true, type cannot be used directly in instance documents -->
            mixed="false" <!-- If true, allows mixed content (text and elements) -->
            block="" <!-- Prevents certain types of derivation: "extension", "restriction", or "#all" -->
            final=""> <!-- Prevents derivation by extension or restriction: "extension", "restriction", or "#all" -->
        (annotation?, ((simpleContent | complexContent | ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))))
        </xs:complexType>
        
      • simpleContent
        Used when extending or restricting complex types that have simple content (text only, plus attributes).
        <xs:simpleContent
            id="">
        (annotation?, (restriction | extension))
        </xs:simpleContent>
        
      • complexContent
        Used when extending or restricting complex types that have complex content (child elements).
        Required when deriving from another complex type.
        <xs:complexContent
            id=""
            mixed="false"> <!-- If true, allows mixed content (text and elements) -->
        (annotation?, (restriction | extension))
        </xs:complexContent>
        
    • Content Model Compositors
      • sequence
        Requires child elements to appear in the specified order.
        Most common compositor for ordered content.
        <xs:sequence
            id=""
            minOccurs="1"
            maxOccurs="1">
        (annotation?, (element | group | choice | sequence | any)*)
        </xs:sequence>
        
      • choice
        Allows exactly one of the child elements to appear.
        Used for mutually exclusive alternatives.
        <xs:choice
            id=""
            minOccurs="1"
            maxOccurs="1">
        (annotation?, (element | group | choice | sequence | any)*)
        </xs:choice>
        
      • all
        Requires all child elements to appear exactly once, but in any order.
        <xs:all
            id=""
            minOccurs="1" <!-- Can only be 0 or 1 (not higher values) -->
            maxOccurs="1"> <!-- Must always be 1 for xs:all -->
        (annotation?, element*)
        </xs:all>
        
      • group
        Groups elements for reuse across multiple complex types.
        Can be defined globally (with name) or referenced (with ref).
        <xs:group
            id=""
            name=""
            ref=""
            minOccurs="1"
            maxOccurs="1">
        (annotation?, (all | choice | sequence)?)
        </xs:group>
        
    • Type Derivation Methods
      • restriction
        Creates a new type by restricting the value space of an existing type.
        <xs:restriction
            id=""
            base=""> <!-- The type being restricted (required) (example: xs:string) -->
        (annotation?, (simpleType?, (minExclusive | minInclusive | maxExclusive | maxInclusive | totalDigits | fractionDigits | length | minLength | maxLength | enumeration | whiteSpace | pattern)*))
        </xs:restriction>
        
      • extension
        Creates a new type by extending an existing type with additional elements or attributes.
        <xs:extension
            id=""
            base=""> <!-- The type being extended (required) (example: xs:int) -->
        (annotation?, ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))
        </xs:extension>
        
      • list
        Creates a list type where values are space-separated instances of the item type.
        <xs:list
            id=""
            itemType=""> <!-- The type of each item in the list (example: xs:string) -->
        (annotation?, simpleType?)
        </xs:list>
        
      • union
        Creates a union type that can hold values from any of the member types.
        <xs:union
            id=""
            memberTypes=""> <!-- Space-separated list of type names -->
        (annotation?, simpleType*)
        </xs:union>
        
    • Numeric Constraints
      • minExclusive
        Constrains values to be greater than the specified value.
        Applicable to: Numeric and date/time types.
        <xs:minExclusive
            id=""
            value=""
            fixed="false">
        (annotation?)
        </xs:minExclusive>
        
      • maxExclusive
        Constrains values to be less than the specified value.
        Applicable to: Numeric and date/time types.
        <xs:maxExclusive
            id=""
            value=""
            fixed="false">
        (annotation?)
        </xs:maxExclusive>
        
      • minInclusive
        Constrains values to be greater than or equal to the specified value.
        Applicable to: Numeric and date/time types.
        <xs:minInclusive
            id=""
            value=""
            fixed="false">
        (annotation?)
        </xs:minInclusive>
        
      • maxInclusive
        Constrains values to be less than or equal to the specified value.
        Applicable to: Numeric and date/time types.
        <xs:maxInclusive
            id=""
            value=""
            fixed="false">
        (annotation?)
        </xs:maxInclusive>
        
      • totalDigits
        Constrains the total number of digits in decimal numbers.
        Applicable to: decimal and types derived from decimal.
        <xs:totalDigits
            id=""
            value=""
            fixed="false">
        (annotation?)
        </xs:totalDigits>
        
      • fractionDigits
        Constrains the number of fractional digits in decimal numbers.
        Applicable to: decimal and types derived from decimal.
        <xs:fractionDigits
            id=""
            value=""
            fixed="false">
        (annotation?)
        </xs:fractionDigits>
        
    • Length Constraints
      • length
        Constrains the exact length of strings, lists, or binary data.
        Applicable to: string types, list types, and binary types.
        <xs:length
            id=""
            value=""
            fixed="false">
        (annotation?)
        </xs:length>
        
      • minLength
        Constrains the minimum length of strings, lists, or binary data.
        Applicable to: string types, list types, and binary types.
        <xs:minLength
            id=""
            value=""
            fixed="false">
        (annotation?)
        </xs:minLength>
        
      • maxLength
        Constrains the maximum length of strings, lists, or binary data.
        Applicable to: string types, list types, and binary types.
        <xs:maxLength
            id=""
            value=""
            fixed="false">
        (annotation?)
        </xs:maxLength>
        
    • String & Pattern Constraints
      • pattern
        Constrains values to match a regular expression pattern.
        Multiple pattern elements are combined with OR logic.
        Applicable to: string types and types derived from string.
        <xs:pattern
            id=""
            value=""> <!-- Regular expression pattern (e.g., "[A-Za-z0-9]+", "\d{3}-\d{2}-\d{4}") -->
        (annotation?)
        </xs:pattern>
        
      • whiteSpace
        Controls whitespace handling in string values:
        • preserve: All whitespace is preserved.
        • replace: Tabs and newlines are replaced with spaces.
        • collapse: Leading/trailing whitespace is removed, internal whitespace is normalized.
        <xs:whiteSpace
            id=""
            value="preserve" <!-- Whitespace handling strategy: "preserve", "replace", "collapse" -->
            fixed="false"> <!-- If true, derived types cannot change this facet -->
        (annotation?)
        </xs:whiteSpace>
        
      • enumeration
        Constrains a type to a specific set of values.
        Multiple enumeration elements can be used to define all valid values.
        <xs:enumeration
            id=""
            value="">
        (annotation?)
        </xs:enumeration>
        
    • Identity Constraints
      • key
        Defines a key constraint (similar to primary key in databases).
        Requirements: Must have selector and one or more field elements with XPath expressions.
        <xs:key
            id=""
            name="">
        (annotation?, (selector, field+))
        </xs:key>
        
      • keyref
        Defines a key reference constraint (similar to foreign key in databases).
        <xs:keyref
            id=""
            name=""
            refer=""> <!-- References the name of a key or unique constraint -->
        (annotation?, (selector, field+))
        </xs:keyref>
        
      • unique
        Defines a uniqueness constraint (similar to unique constraint in databases).
        Difference from key: Allows null values, key does not.
        <xs:unique
            id=""
            name="">
        (annotation?, (selector, field+))
        </xs:unique>
        
      • selector
        Defines the XPath expression that selects nodes for identity constraints.
        Used within key, keyref, and unique elements.
        <xs:selector
            id=""
            xpath=""> <!-- XPath expression to select context nodes (e.g., ".//book") -->
        (annotation?)
        </xs:selector>
        
      • field
        Defines the XPath expression that selects the field values for identity constraints.
        Used within key, keyref, and unique elements after selector.
        <xs:field
            id=""
            xpath=""> <!-- XPath expression to select field value (e.g., "@id" or "title") -->
        (annotation?)
        </xs:field>
        
    • Documentation & Metadata
      • annotation
        Provides human-readable documentation and application-specific information within schemas.
        <xs:annotation
            id="">
        (appinfo | documentation)*
        </xs:annotation>
        
      • documentation
        Provides human-readable documentation within annotation elements.
        <xs:documentation
            source="" <!-- URI reference to external documentation -->
            xml:lang=""> <!-- Language code (e.g., "en", "fr", "de") -->
        (#PCDATA | any)*
        </xs:documentation>
        
      • appinfo
        Provides application-specific information within annotation elements.
        <xs:appinfo
            source=""> <!-- URI reference to external application information -->
        (#PCDATA | any)*
        </xs:appinfo>
        
    • Schema Structure & Organization
      • import
        Imports components from a schema in a different namespace.
        <xs:import
            id=""
            namespace="" <!-- Target namespace of the imported schema; use ##targetNamespace or ##local -->
            schemaLocation=""> <!-- Location of the schema file (optional) -->
        (annotation?)
        </xs:import>
        
      • include
        Includes components from a schema in the same namespace.
        <xs:include
            id=""
            schemaLocation=""> <!-- Location of the schema file (required) -->
        (annotation?)
        </xs:include>
        
      • redefine
        Includes and redefines components from another schema.
        Allows modification of included types and groups.
        <xs:redefine
            id=""
            schemaLocation="">
        (annotation?, (simpleType | complexType | group | attributeGroup)*)
        </xs:redefine>
        
      • notation
        Declares a notation for use with NOTATION data types.
        <xs:notation
            id=""
            name=""
            public="" <!-- Public identifier for the notation -->
            system=""> <!-- System identifier (URI) for the notation -->
        (annotation?)
        </xs:notation>
        
  7. Attributes References
    • use
      Controls whether an attribute is required, optional, or prohibited.
      Used in attribute declarations within complex types.
      use="optional" <!-- Default: Attribute is optional -->
      use="required" <!-- Attribute must be present -->
      use="prohibited" <!-- Attribute must not be present (used in restrictions) -->
      
    • namespace
      Specifies which namespaces are allowed for wildcard elements and attributes.
      Used with xs:any and xs:anyAttribute to control namespace matching.
      namespace="##any" <!-- Default: Any namespace including no namespace -->
      namespace="##other" <!-- Any namespace other than the target namespace -->
      namespace="##targetNamespace" <!-- Only the target namespace -->
      namespace="##local" <!-- Only elements/attributes with no namespace -->
      namespace="http://example.com" <!-- Specific namespace URI -->
      namespace="##any ##local" <!-- Multiple values separated by spaces -->
      
    • processContents
      Determines how the XML processor handles validation of content from other namespaces.
      • Strict Validation: All elements and attributes must be declared in the schema and validate successfully
      • Lax Validation: Elements and attributes are validated only if their declarations are available
      • Skip Validation: No validation is performed (used with xs:any and xs:anyAttribute)
      <!-- Strict validation -->
      <xs:any namespace="##other" processContents="strict" /> <!-- Default: Must obtain schemas to validate -->
      
      <!-- Lax validation -->
      <xs:any namespace="##any" processContents="lax" /> <!-- Validate only if schema is available -->
      
      <!-- Skip validation -->
      <xs:any namespace="##local" processContents="skip" /> <!-- No validation - any well-formed content allowed -->
      
    • block
      Controls which types of derivation are blocked for the element or type.
      Used in element declarations and complex type definitions to prevent certain derivations.
      block="#all" <!-- Blocks all derivations -->
      block="extension" <!-- Blocks derivation by extension -->
      block="restriction" <!-- Blocks derivation by restriction -->
      block="substitution" <!-- Blocks substitution -->
      
    • final
      Prevents derivation of new types from the current type.
      Used in type definitions to control which derivation methods are allowed.
      final="#all" <!-- Prevents all derivations -->
      final="extension" <!-- Prevents derivation by extension -->
      final="restriction" <!-- Prevents derivation by restriction -->
      final="list" <!-- Prevents derivation by list (simple types only) -->
      final="union" <!-- Prevents derivation by union (simple types only) -->
      
© 2025 mtitek