Skip to main content

Search 400 pages — tools, formats, elements, namespaces, directory, comparisons, XPath, datatypes, glossary, parse errors, schema errors, use cases, guides, blog and product.

XML Schema (XSD)

<xs:import>

Makes schema components from a different target namespace available to the importing schema.

import crosses a namespace boundary. namespace identifies the component namespace; schemaLocation is only a retrieval hint.

Imports belong near the start of xs:schema. A processor may resolve the namespace through a catalog instead of the supplied location.

What it contains

Nothing — this element holds a value rather than other elements. Its content is text, and the constraints below are what that text has to be.

Attributes

  • namespaceoptionalThe target namespace of the components to import.
  • schemaLocationoptionalA location hint that a resolver may replace or ignore.

Cardinality and constraints

Any number before schema component declarations.

  • Used for a different target namespace.
  • schemaLocation is a hint and may be resolved externally.

What our validator does

The XML validator checks that both examples are well-formed. It does not enforce this vocabulary's semantic content model, so the broken example is intentionally reported as valid XML.

We do not catch this one

This document is well-formed XML but violates a SOAP or XML Schema vocabulary rule. XML syntax alone cannot detect that defect; use a SOAP-aware processor or an XSD validator when conformance matters.

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.

broken
<?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>
No issue reported. This defect passes our checks.
fixed
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 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="Sku"/></xs:sequence><xs:attribute name="active" type="xs:boolean"/></xs:complexType>
  <xs:element name="product" type="Product"/>
</xs:schema>
No errors. Warnings may remain — a conforming feed can still be missing a self link — but nothing here is wrong.

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.