AAmit’s LibraryLEARN · PRACTISE · REFLECT

Computers · Programming Atlas

XML Schema 1.0 Introduction

Single-document XSD 1.0 validation: values and lexical forms, bounds, sequence order, occurrence limits, attributes, enumerations, namespaces and optional/nil distinctions. No XSD 1.1, assertion language, schema composition, derivation, identity constraints or full standards coverage.

Audience: Learners who can read a small XML document and invoke an installed command-line tool.

Practice: 60 to 90 minutes.

Website reference edition

This introductory material is available here for reading and practice planning. New offline workbench exports, PDF and ZIP editions for these additions are not published. The released Atlas 0.11 downloads cover the earlier 19 packs only. These pages do not run teaching code or contact an AI service.

Runtime and boundaries

Use the installed /usr/bin/xmllint with XML_CATALOG_FILES and SGML_CATALOG_FILES empty and --nonet. The test harness supplies explicit arguments without a shell and a five-second deadline for each owned process. This old installed parser is recorded for reproducible learning, not recommended for hostile documents. --nonet is not a local-file sandbox. These authored fixtures contain no external-resource constructs. Local examples were tested on macOS 27.0.1 arm64; no complete standards conformance or other-platform result is claimed. No browser runs teaching code.

Introductory module · 2 exercises

Lessons

Separate three kinds of rejection

The authored schema is an XML document; it must also be a legal schema. A well-formed instance can still violate that schema. Record which stage failed. A valid instance result is not a claim that the data is safe, authorized or meaningful for every application. The recorded fixtures return 5 for invalid schema preparation, 3 for a well-formed invalid instance and 1 for malformed XML. These are observed CLI outcomes for this installed build, not universal codes for every parser failure.

Choose a value type and small bounds

The minutes example starts with an integer restriction and inclusive limits. Predict zero, the upper bound, a negative value and numeric text with a decimal point. Validation checks the selected type; it does not rewrite source bytes. The signed, zero-padded example deliberately remains unchanged.

Describe shape separately from content

A sequence gives child order. Occurrence bounds control how many children may appear, while an attribute can be required independently. The shape example uses one title and an optional minutes child, then checks a reversed order and a missing id.

Names and whitespace have rules

Namespace URIs distinguish same-spelled element names. The namespace example requires qualified elements and an unqualified id attribute. The token enumeration example demonstrates collapsed whitespace; its valid spellings are deliberate rather than inferred from how a UI might display them.

Missing, empty and nil are different choices

The optional integer exercise compares omission, explicit xsi:nil and empty text. The collection exercise then combines a bounded repeating shape with a shared local type. Both are small introductions: schema imports, complex identity rules and XSD 1.1 assertions need later work.

Reference cards

Schema namespace: http://www.w3.org/2001/XMLSchema

Identifies XSD schema vocabulary; the prefix spelling is arbitrary.

Integer datatype: xs:integer

Whole-number value type with its own lexical rules.

Bounds: xs:minInclusive / xs:maxInclusive

Include the stated boundary values.

Children: xs:sequence

Require the declared child order.

Occurrences: minOccurs / maxOccurs

Defaults are one; set optional and bounded repetition explicitly.

Attributes: use="required"

Require presence separately from value type.

Namespaces: targetNamespace / elementFormDefault

Declare the vocabulary and local element qualification policy.

Nil: nillable="true" / xsi:nil="true"

Allow an explicit nil element; omission and empty text remain different cases.

Support file: XML Schema 1.0 Introduction practice instructions.txt
Staged content only; no browser export acceptance or release.
Use the fixed commands shown with the authored input files. The local validator also exercises separate expected rejections. No external inputs, runtime downloads or installations.
Use the installed /usr/bin/xmllint with XML_CATALOG_FILES and SGML_CATALOG_FILES empty and --nonet. The test harness supplies explicit arguments without a shell and a five-second deadline for each owned process. This old installed parser is recorded for reproducible learning, not recommended for hostile documents. --nonet is not a local-file sandbox. These authored fixtures contain no external-resource constructs. Local examples were tested on macOS 27.0.1 arm64; no complete standards conformance or other-platform result is claimed. No browser runs teaching code.

Examples and practice

All code and values below are inert reading material. Preserve each exact filename and companion when making your own practice copy.

XSD 01 - Bound minutes

The type checks integer values from zero through 120. A lexical spelling such as +020 has the same value here; validation does not canonicalize the file.

Filename: XSD 01 Bound minutes.xsd

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="Minutes"><xs:restriction base="xs:integer"><xs:minInclusive value="0"/><xs:maxInclusive value="120"/></xs:restriction></xs:simpleType>
<xs:element name="minutes" type="Minutes"/>
</xs:schema>

Expected output:

Example instance validates (exit 0; diagnostic on stderr).

Recorded invocation:

XML_CATALOG_FILES= SGML_CATALOG_FILES= /usr/bin/xmllint --nonet --noout --schema "XSD 01 Bound minutes.xsd" "XSD 01 Input.xml"

Companion: XSD 01 Input.xml

<minutes>20</minutes>

Typed result contract

variant
xsd
summary
Example instance validates (exit 0; diagnostic on stderr).
stdout

Type: string

""
exit status

Type: integer

0
stderr
match
contains
value
validates
validity

Type: boolean

true

Authored case table

variant
xsd
rows
  1. name
    example
    input

    Type: string

    "<minutes>20</minutes>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    0
    stderr contains

    Type: string

    "validates"
    validity

    Type: boolean

    true
  2. name
    lower boundary
    input

    Type: string

    "<minutes>0</minutes>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    0
    stderr contains

    Type: string

    "validates"
    validity

    Type: boolean

    true
  3. name
    upper boundary
    input

    Type: string

    "<minutes>120</minutes>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    0
    stderr contains

    Type: string

    "validates"
    validity

    Type: boolean

    true
  4. name
    signed leading zeros
    input

    Type: string

    "<minutes>+020</minutes>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    0
    stderr contains

    Type: string

    "validates"
    validity

    Type: boolean

    true
  5. name
    above maximum
    input

    Type: string

    "<minutes>121</minutes>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    3
    stderr contains

    Type: string

    "maxInclusive"
    validity

    Type: boolean

    false
  6. name
    fractional spelling
    input

    Type: string

    "<minutes>20.0</minutes>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    3
    stderr contains

    Type: string

    "not a valid value"
    validity

    Type: boolean

    false
XSD 02 - Describe a record

The sequence fixes child order. The id attribute is required, while minutes is optional. xs:string permits an empty title: use a length restriction later if that is not the intended contract.

Filename: XSD 02 Describe a record.xsd

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="record"><xs:complexType><xs:sequence><xs:element name="title" type="xs:string"/><xs:element name="minutes" type="xs:integer" minOccurs="0"/></xs:sequence><xs:attribute name="id" type="xs:string" use="required"/></xs:complexType></xs:element>
</xs:schema>

Expected output:

Example instance validates (exit 0; diagnostic on stderr).

Recorded invocation:

XML_CATALOG_FILES= SGML_CATALOG_FILES= /usr/bin/xmllint --nonet --noout --schema "XSD 02 Describe a record.xsd" "XSD 02 Input.xml"

Companion: XSD 02 Input.xml

<record id="a"><title>Read</title><minutes>20</minutes></record>

Typed result contract

variant
xsd
summary
Example instance validates (exit 0; diagnostic on stderr).
stdout

Type: string

""
exit status

Type: integer

0
stderr
match
contains
value
validates
validity

Type: boolean

true

Authored case table

variant
xsd
rows
  1. name
    example
    input

    Type: string

    "<record id=\"a\"><title>Read</title><minutes>20</minutes></record>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    0
    stderr contains

    Type: string

    "validates"
    validity

    Type: boolean

    true
  2. name
    optional child absent
    input

    Type: string

    "<record id=\"a\"><title>Read</title></record>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    0
    stderr contains

    Type: string

    "validates"
    validity

    Type: boolean

    true
  3. name
    missing id
    input

    Type: string

    "<record><title>Read</title></record>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    3
    stderr contains

    Type: string

    "required but missing"
    validity

    Type: boolean

    false
  4. name
    reversed children
    input

    Type: string

    "<record id=\"a\"><minutes>20</minutes><title>Read</title></record>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    3
    stderr contains

    Type: string

    "not expected"
    validity

    Type: boolean

    false
XSD 03 - Choose a token

The token type collapses leading, trailing and repeated whitespace before the enumeration check. The authored case distinguishes value validation from exact lexical spelling.

Filename: XSD 03 Choose a token.xsd

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="mode"><xs:simpleType><xs:restriction base="xs:token"><xs:enumeration value="read"/><xs:enumeration value="pair practice"/></xs:restriction></xs:simpleType></xs:element>
</xs:schema>

Expected output:

Example instance validates (exit 0; diagnostic on stderr).

Recorded invocation:

XML_CATALOG_FILES= SGML_CATALOG_FILES= /usr/bin/xmllint --nonet --noout --schema "XSD 03 Choose a token.xsd" "XSD 03 Input.xml"

Companion: XSD 03 Input.xml

<mode>read</mode>

Typed result contract

variant
xsd
summary
Example instance validates (exit 0; diagnostic on stderr).
stdout

Type: string

""
exit status

Type: integer

0
stderr
match
contains
value
validates
validity

Type: boolean

true

Authored case table

variant
xsd
rows
  1. name
    example
    input

    Type: string

    "<mode>read</mode>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    0
    stderr contains

    Type: string

    "validates"
    validity

    Type: boolean

    true
  2. name
    collapsed whitespace
    input

    Type: string

    "<mode>  pair   practice </mode>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    0
    stderr contains

    Type: string

    "validates"
    validity

    Type: boolean

    true
  3. name
    different case
    input

    Type: string

    "<mode>READ</mode>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    3
    stderr contains

    Type: string

    "enumeration"
    validity

    Type: boolean

    false
  4. name
    empty token
    input

    Type: string

    "<mode> </mode>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    3
    stderr contains

    Type: string

    "enumeration"
    validity

    Type: boolean

    false
XSD 04 - Qualify a record

Both element names belong to the study namespace. The id attribute does not: a default XML namespace does not apply to unprefixed attributes. Prefix spelling may change without changing expanded names.

Filename: XSD 04 Qualify a record.xsd

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:atlas:study" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="record"><xs:complexType><xs:sequence><xs:element name="title" type="xs:string"/></xs:sequence><xs:attribute name="id" type="xs:string" use="required"/></xs:complexType></xs:element>
</xs:schema>

Expected output:

Example instance validates (exit 0; diagnostic on stderr).

Recorded invocation:

XML_CATALOG_FILES= SGML_CATALOG_FILES= /usr/bin/xmllint --nonet --noout --schema "XSD 04 Qualify a record.xsd" "XSD 04 Input.xml"

Companion: XSD 04 Input.xml

<record xmlns="urn:atlas:study" id="a"><title>Read</title></record>

Typed result contract

variant
xsd
summary
Example instance validates (exit 0; diagnostic on stderr).
stdout

Type: string

""
exit status

Type: integer

0
stderr
match
contains
value
validates
validity

Type: boolean

true

Authored case table

variant
xsd
rows
  1. name
    example
    input

    Type: string

    "<record xmlns=\"urn:atlas:study\" id=\"a\"><title>Read</title></record>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    0
    stderr contains

    Type: string

    "validates"
    validity

    Type: boolean

    true
  2. name
    different prefix
    input

    Type: string

    "<s:record xmlns:s=\"urn:atlas:study\" id=\"a\"><s:title>Read</s:title></s:record>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    0
    stderr contains

    Type: string

    "validates"
    validity

    Type: boolean

    true
  3. name
    missing root namespace
    input

    Type: string

    "<record id=\"a\"><title>Read</title></record>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    3
    stderr contains

    Type: string

    "No matching global declaration"
    validity

    Type: boolean

    false
  4. name
    unqualified child
    input

    Type: string

    "<record xmlns=\"urn:atlas:study\" id=\"a\"><title xmlns=\"\">Read</title></record>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    3
    stderr contains

    Type: string

    "not expected"
    validity

    Type: boolean

    false
XSD 05 - Separate missing and nil

Solution: allow omission with minOccurs and explicit nil with nillable. An ordinary empty integer element has no valid integer lexical form. Explicit nil does not permit a text value.

Filename: XSD 05 Separate missing and nil.xsd

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="record"><xs:complexType><xs:sequence><xs:element name="minutes" type="xs:integer" minOccurs="0" nillable="true"/></xs:sequence></xs:complexType></xs:element>
</xs:schema>

Expected output:

Example instance validates (exit 0; diagnostic on stderr).

Recorded invocation:

XML_CATALOG_FILES= SGML_CATALOG_FILES= /usr/bin/xmllint --nonet --noout --schema "XSD 05 Separate missing and nil.xsd" "XSD 05 Input.xml"

Companion: XSD 05 Input.xml

<record><minutes>20</minutes></record>

Typed result contract

variant
xsd
summary
Example instance validates (exit 0; diagnostic on stderr).
stdout

Type: string

""
exit status

Type: integer

0
stderr
match
contains
value
validates
validity

Type: boolean

true

Authored case table

variant
xsd
rows
  1. name
    example
    input

    Type: string

    "<record><minutes>20</minutes></record>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    0
    stderr contains

    Type: string

    "validates"
    validity

    Type: boolean

    true
  2. name
    omitted
    input

    Type: string

    "<record/>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    0
    stderr contains

    Type: string

    "validates"
    validity

    Type: boolean

    true
  3. name
    explicit nil
    input

    Type: string

    "<record xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><minutes xsi:nil=\"true\"/></record>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    0
    stderr contains

    Type: string

    "validates"
    validity

    Type: boolean

    true
  4. name
    empty integer
    input

    Type: string

    "<record><minutes/></record>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    3
    stderr contains

    Type: string

    "not a valid value"
    validity

    Type: boolean

    false
  5. name
    nil with text
    input

    Type: string

    "<record xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><minutes xsi:nil=\"true\">20</minutes></record>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    3
    stderr contains

    Type: string

    "Neither character nor element content"
    validity

    Type: boolean

    false

Practice: Design a minutes field that may be missing or explicitly nil but otherwise must be an integer. Predict all four boundary cases before reading the solution.

XSD 06 - Bound a study list

Solution: this bounded collection reuses the authored Minutes type. It validates each item independently, not a sum across records. Cross-record budgets are a separate application check, not an implied XSD 1.0 assertion.

Filename: XSD 06 Bound a study list.xsd

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="Minutes"><xs:restriction base="xs:integer"><xs:minInclusive value="0"/><xs:maxInclusive value="120"/></xs:restriction></xs:simpleType>
<xs:element name="study"><xs:complexType><xs:sequence><xs:element name="item" minOccurs="1" maxOccurs="3"><xs:complexType><xs:attribute name="minutes" type="Minutes" use="required"/></xs:complexType></xs:element></xs:sequence></xs:complexType></xs:element>
</xs:schema>

Expected output:

Example instance validates (exit 0; diagnostic on stderr).

Recorded invocation:

XML_CATALOG_FILES= SGML_CATALOG_FILES= /usr/bin/xmllint --nonet --noout --schema "XSD 06 Bound a study list.xsd" "XSD 06 Input.xml"

Companion: XSD 06 Input.xml

<study><item minutes="20"/><item minutes="10"/></study>

Typed result contract

variant
xsd
summary
Example instance validates (exit 0; diagnostic on stderr).
stdout

Type: string

""
exit status

Type: integer

0
stderr
match
contains
value
validates
validity

Type: boolean

true

Authored case table

variant
xsd
rows
  1. name
    example
    input

    Type: string

    "<study><item minutes=\"20\"/><item minutes=\"10\"/></study>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    0
    stderr contains

    Type: string

    "validates"
    validity

    Type: boolean

    true
  2. name
    minimum list
    input

    Type: string

    "<study><item minutes=\"0\"/></study>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    0
    stderr contains

    Type: string

    "validates"
    validity

    Type: boolean

    true
  3. name
    maximum list
    input

    Type: string

    "<study><item minutes=\"1\"/><item minutes=\"2\"/><item minutes=\"3\"/></study>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    0
    stderr contains

    Type: string

    "validates"
    validity

    Type: boolean

    true
  4. name
    empty list
    input

    Type: string

    "<study/>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    3
    stderr contains

    Type: string

    "Missing child"
    validity

    Type: boolean

    false
  5. name
    too many items
    input

    Type: string

    "<study><item minutes=\"1\"/><item minutes=\"2\"/><item minutes=\"3\"/><item minutes=\"4\"/></study>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    3
    stderr contains

    Type: string

    "not expected"
    validity

    Type: boolean

    false
  6. name
    out of range item
    input

    Type: string

    "<study><item minutes=\"121\"/></study>"
    stdout

    Type: string

    ""
    exit status

    Type: integer

    3
    stderr contains

    Type: string

    "maxInclusive"
    validity

    Type: boolean

    false

Practice: Write a study list with one to three items and each minutes attribute between zero and 120. Explain why this does not bound the total list duration.

Separate expected outcome: xsd-bad-schema
id
xsd-bad-schema
variant
xsd-prepare-or-parse
category
Schema preparation error; no valid schema
inputs
schema

Type: string

"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n<xs:element name=\"minutes\" type=\"xs:NoSuchType\"/>\n</xs:schema>\n"
xml

Type: string

"<minutes>2</minutes>"
stdout

Type: string

""
exit status

Type: integer

5
stderr
match
contains
value
does not resolve
execution meaning
Recorded command outcome; separate from successful teaching examples.
individual download control
false
Separate expected outcome: xsd-malformed-xml
id
xsd-malformed-xml
variant
xsd-prepare-or-parse
category
Malformed instance XML, separate from schema-invalid well-formed instance
inputs
schema

Type: string

"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n<xs:simpleType name=\"Minutes\"><xs:restriction base=\"xs:integer\"><xs:minInclusive value=\"0\"/><xs:maxInclusive value=\"120\"/></xs:restriction></xs:simpleType>\n<xs:element name=\"minutes\" type=\"Minutes\"/>\n</xs:schema>\n"
xml

Type: string

"<minutes>2"
stdout

Type: string

""
exit status

Type: integer

1
stderr
match
contains
value
Premature end
execution meaning
Recorded command outcome; separate from successful teaching examples.
individual download control
false

Prompt templates

Planning text only; no AI service or export control is activated here.

Build a small contract
Create an original tiny example with explicit inputs and expected results. Keep the stated version, classify the query or schema role accurately and state what remains outside the introduction. Language: {language}. Goal: {goal}. Runtime: {runtime}. Constraints: {constraints}.
Debug the correct stage
Use the smallest authored reproducer and exact diagnostic. Separate XML parsing, expression/schema preparation and result/instance validation. Do not weaken rules just to make a case pass. Language: {language}. Goal: {goal}. Runtime: {runtime}. Constraints: {constraints}.
Test boundaries
Propose normal, missing, empty, namespace and boundary cases. Keep expected rejection separate from a successful query or valid instance; never claim tests were executed without evidence. Language: {language}. Goal: {goal}. Runtime: {runtime}. Constraints: {constraints}.
Refactor with preserved behavior
Simplify the authored query or schema while preserving explicit accepted/rejected cases and namespace meaning. Do not add external resources or generated query syntax from user text. Language: {language}. Goal: {goal}. Runtime: {runtime}. Constraints: {constraints}.
Document assumptions
Explain the input contract, namespace policy, version, installed tool and actual observed results. Distinguish this introductory subset from deep or full-language coverage. Language: {language}. Goal: {goal}. Runtime: {runtime}. Constraints: {constraints}.

Historical measure scopes

These measures describe separate, overlapping source-example checks. They are not additive totals or website acceptance results.

  1. name
    teaching_examples
    count
    6
    unit
    examples including solutions
    scope
    Historical root module evidence; overlapping measures are not additive.
    tested on
    2026-10-28
    runtime
    xmllint / libxml2 2.9.13; macOS 27.0.1 arm64
  2. name
    exercise_solutions
    count
    2
    unit
    solutions included in examples
    scope
    Historical root module evidence; overlapping measures are not additive.
    tested on
    2026-10-28
    runtime
    xmllint / libxml2 2.9.13; macOS 27.0.1 arm64
  3. name
    query_result_cases
    count
    0
    unit
    query cases
    scope
    Historical root module evidence; overlapping measures are not additive.
    tested on
    2026-10-28
    runtime
    xmllint / libxml2 2.9.13; macOS 27.0.1 arm64
  4. name
    schema_instance_cases
    count
    29
    unit
    schema instance cases
    scope
    Historical root module evidence; overlapping measures are not additive.
    tested on
    2026-10-28
    runtime
    xmllint / libxml2 2.9.13; macOS 27.0.1 arm64
  5. name
    separate_error_outcomes
    count
    2
    unit
    separate error outcomes
    scope
    Historical root module evidence; overlapping measures are not additive.
    tested on
    2026-10-28
    runtime
    xmllint / libxml2 2.9.13; macOS 27.0.1 arm64

Recorded test scope

status
passed for local introductory examples only
tested on
2026-10-28
runtime
xmllint / libxml2 2.9.13; macOS 27.0.1 arm64
teaching examples
6
exercise solutions
2
query result cases
0
schema instance cases
29
separate error outcomes
2
scope
Example results only; browser/export and release gates are open.

These are dated source-example results, not website browser, export, PDF or cross-platform acceptance.

Further reading

References are the reviewed source snapshot; they have not been rechecked at website publication time.