XML Schema (XSD)
<xs:schema>
The XML Schema document element, where namespaces, global declarations, imports, and defaults are assembled.
A schema document starts with xs:schema and identifies the vocabulary it describes through targetNamespace. Global elements and types beneath it become reusable named components.
elementFormDefault controls qualification of local elements in instance documents; it does not change the schema document's own xs namespace.
- Format
- XML Schema (XSD)
- Namespace
- XML Schema Definition (XSD)
- Parent
- None — this is the document element
- How many
- Exactly one, as the schema document element.
What it contains
xs:elementany numberxs:complexTypeany numberxs:simpleTypeany numberxs:importany numberxs:includeany number
Attributes
targetNamespaceoptionalNames the namespace governed by the schema; omission creates a no-namespace schema.
What our validator does
The XML validator checks well-formedness and selected SOAP or XML Schema vocabulary rules. It reports this content-model defect with a concrete repair while staying silent on rules it cannot establish from one document.
Broken and fixed
Both documents below are well-formed XML — that is the point of this corpus — and both are run through the validator on every test run. The verdicts here are what it returned, not what we expect it to.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:example:catalog">
<xs:complexType name="Product"><xs:attribute name="active" type="xs:boolean" maxOccurs="2"/></xs:complexType>
</xs:schema>xs:attribute cannot use minOccurs or maxOccurs; attributes use the use attribute instead.<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="urn:example:catalog" targetNamespace="urn:example:catalog" elementFormDefault="qualified">
<xs:simpleType name="Sku"><xs:restriction base="xs:string"><xs:minLength value="1"/></xs:restriction></xs:simpleType>
<xs:complexType name="Product"><xs:sequence><xs:element name="sku" type="tns:Sku"/></xs:sequence><xs:attribute name="active" type="xs:boolean"/></xs:complexType>
<xs:element name="product" type="tns:Product"/>
</xs:schema>Where it reaches
- FormatsXML Schema (XSD)The XSD format page places this element in the complete document model.
- NamespacesXML Schema Definition (XSD)The exact namespace URI that gives <xs:schema> its vocabulary meaning.
- ToolsXSD validatorCheck schema-document structure before validating an instance against it.
Related elements
- <xs:element>Declares an element's name, type, occurrence range, defaulting, and whether an explicit xsi:nil is allowed.
- <xs:complexType>Defines structured element content: child elements, attributes, mixed text, and derivation from another type.
- <xs:import>Makes schema components from a different target namespace available to the importing schema.
Get started
Bring order to the XML your team can't afford to ignore.
Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.