ConvertCSV

XML Schema (XSD) Explained: Types, Validation, and Examples

By Convert CSV Editorial TeamLast updated August 1, 2026

Learn XML Schema (XSD): elements, types, attributes, and how to validate documents. Practical examples for partner feeds and CSV-generated XML.

What Is an XML Schema?

An XML Schema Definition (XSD) is a contract that describes which elements and attributes are allowed, in what order, and with which data types. If a document violates the schema, validators reject it—even when the XML is well-formed.

Partners publish XSDs so every supplier sends the same shape. Treat the XSD as source of truth for imports and exports.

Core Building Blocks

You only need a handful of constructs to read most partner schemas.

ConstructPurpose
xs:elementDeclares an element name and type
xs:attributeDeclares an attribute on an element
xs:complexTypeStructure with children and/or attributes
xs:simpleTypeConstrained text/number (patterns, enums)
xs:sequenceOrdered list of child elements
minOccurs / maxOccursCardinality (optional, required, repeating)

A Minimal XSD Example

This schema describes a list of orders with a required email and a decimal amount.

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           elementFormDefault="qualified">
  <xs:element name="records">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="record" maxOccurs="unbounded">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="order_id" type="xs:string"/>
              <xs:element name="email" type="xs:string"/>
              <xs:element name="amount" type="xs:decimal"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Common Simple Types

Built-in types cover most tabular fields you would export from CSV.

  • xs:string — text, IDs, emails (often with a pattern facet).
  • xs:decimal / xs:integer — amounts and counts.
  • xs:boolean — true/false (not "yes"/"no" unless restricted).
  • xs:date / xs:dateTime — ISO-style dates.
  • xs:token — string with normalized whitespace.

How to Validate Against an XSD

Validation belongs in CI and in the upload checklist.

xmllint --noout --schema orders.xsd orders.xml

Interpret failures

Messages usually name the element, the expected type, and the line number. Fix the source data (often a CSV column), regenerate XML, and validate again—do not permanently hand-patch production files.

XSD and CSV Workflows

When XML is generated from a spreadsheet, map CSV columns to schema elements one-to-one. Rename headers to match element names, cast dates to xs:date shapes, and keep amounts as plain decimals without currency symbols.

Convert CSV Online’s CSV to XML Converter is useful for a first draft; then validate with the partner XSD before SFTP.

Namespaces in Schemas

Many XSDs declare a targetNamespace. Instance documents must use that namespace on the root (default or prefixed). A valid local structure with the wrong namespace still fails validation.

Real-World Examples

Where XSDs decide whether a feed is accepted.

Marketplace onboarding

A retailer must match a published catalog XSD; optional fields in the spreadsheet become optional elements with minOccurs="0".

Government filing

Enums and patterns reject free-text status codes that looked fine in Excel.

Internal contract tests

CI validates sample XML fixtures against the team XSD on every pull request.

Common Mistakes

Schema misunderstandings cause "mystery" rejections.

  • Ignoring targetNamespace.
  • Sending "Yes"/"No" where xs:boolean is required.
  • Putting currency symbols in xs:decimal fields.
  • Reordering children under xs:sequence.
  • Treating well-formedness as schema validity.

Best Practices

Treat the XSD like an API contract.

  • Version schemas and document breaking changes.
  • Keep sample XML next to the XSD in Git.
  • Validate every generated file in CI.
  • Prefer regenerating from CSV over hand-editing XML.
  • Flatten with XML to CSV when humans need to fix values.

Why Use Convert CSV Online?

Convert CSV Online is free, browser-based, and requires no account for everyday conversions. Build candidate XML from CSV, then validate locally with xmllint against the partner XSD. Client-side workflows work on Windows, macOS, and Linux browsers.

Fix values in a table

When validation fails on data—not structure—edit the CSV and regenerate instead of wrestling with tags.

Conclusion

XSD turns XML from "looks okay" into a testable contract. Learn elements, types, and cardinality, validate early, and keep spreadsheet sources aligned with the schema.

FAQ

What is an XML Schema (XSD)?

An XSD is a W3C language that describes the allowed structure and data types of an XML document. Validators use it to accept or reject instance documents.

How is XSD different from well-formed XML?

Well-formed XML follows markup rules. Schema-valid XML also matches the element names, types, and constraints defined in an XSD.

How do I validate XML against an XSD?

Use xmllint --schema file.xsd file.xml, or a schema-aware library/IDE. Fix errors at the source and re-validate.

Do I need an XSD for every XML file?

Not always—but partner feeds, government filings, and enterprise imports almost always provide one. Use it.

Can CSV map to an XSD?

Yes. Align column headers with element names and types, convert CSV to XML, then validate against the XSD.

What does minOccurs="0" mean?

The element is optional. Missing it is valid; sending the wrong type for it is not.

References

Convert your CSV in the browser

Preview, clean, and convert CSV files free with Convert CSV Online—no installation and no account required for everyday conversions.